问题
Here's the current scenario -
I have multiple S3 Buckets, which have SQS events configured for PUTs of Objects from a FTP, which I have configured using S3FS.
Also, I have multiple Directories on an EC2, on which a User can PUT an object, which gets synced with the different S3 buckets (using S3FS), which generate SQS events(using S3's SQS events).
Here's what I need to achieve,
Instead of Multiple S3 buckets, I need to consolidate the logic on Folder level,
ie. I have now created Different Folders for each Bucket that I had created previously, I have created separate SQS events for PUT in individual Folders.
Now the Bucket level logic of S3FS, I want to tweak for Folder level in a Single S3 bucket.
ie. I want to create 3 different Directories oon the EC2, eg A,B,C.
If I PUT an object in Directory A of the EC2, the object must get synced with Folder A in the S3 bucket,
Similarly for Directory B and folder B of S3 and Directory C on EC2 and Folder C on the S3.
Here are the steps I created for installing S3FS -
Steps -
ssh into the EC2
sudo apt-get install automake autotools-dev g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config
git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse
./autogen.sh
./configure
make
sudo make install
Mounting S3 Bucket to File System
echo access-key-id:secret-access-key > /etc/passwd-s3fs
chmod 600 /etc/passwd-s3fs
mkdir /mnt/bucketname
echo s3fs#bucketname /mnt/bucketname fuse _netdev,rw,nosuid,nodev,allow_other 0 0 >> /etc/fstab
mount -a
Now these steps achieve sync between a particular Directory on the EC2 and the S3 bucket,
How do I tweak this to sync say 2 different Directories on the EC2 with 2 different Folders on the S3.
I am a Linux and AWS newbie, Please help me out.
回答1:
Do not mount the S3 bucket to the file system. Use AWS S3 CLI and Cron to Sync the EC2 Directory with the S3 Bucket Directory.
- Install S3CMD on the EC2 instance (http://tecadmin.net/install-s3cmd-manage-amazon-s3-buckets/#)
- Start a cron job for achieving the Sync with the local directory and the S3 Bucket Subfolder.
Create a Script File for example "script.sh"
#/bin/bash
aws s3 sync /path/to/folder/A s3://mybucket/FolderA
aws s3 sync /path/to/folder/B s3://mybucket/FolderB
aws s3 sync /path/to/folder/C s3://mybucket/FolderC
Start a cron job for some thing like this:
* * * * * /root/scripts/script.sh
And you will achieve your use case.
来源:https://stackoverflow.com/questions/38598916/aws-s3fs-how-to