AWS S3FS How to

狂风中的少年 提交于 2020-06-17 00:55:19

问题


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 -

  1. ssh into the EC2

  2. sudo apt-get install automake autotools-dev g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config

  3. git clone https://github.com/s3fs-fuse/s3fs-fuse.git

  4. cd s3fs-fuse

  5. ./autogen.sh

  6. ./configure

  7. make

  8. sudo make install

Mounting S3 Bucket to File System

  1. echo access-key-id:secret-access-key > /etc/passwd-s3fs

  2. chmod 600 /etc/passwd-s3fs

  3. mkdir /mnt/bucketname

  4. echo s3fs#bucketname /mnt/bucketname fuse _netdev,rw,nosuid,nodev,allow_other 0 0 >> /etc/fstab

  5. 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.

  1. Install S3CMD on the EC2 instance (http://tecadmin.net/install-s3cmd-manage-amazon-s3-buckets/#)
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!