简体   繁体   中英

AWS EC2 shared folder with S3 without manual sync

I have created an S3 bucket without public access in order to act as a shared folder with a directory of an EC2 instance.

I have assigned a role with a policy to the EC2 instance in order to be able to synchronise data with each other.

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "s3:PutObject",
            "s3:GetObject",
            "s3:DeleteObject"
        ],
        "Resource": "arn:aws:s3:::my-bucket-with-images/*"
    },
    {
        "Effect": "Allow",
        "Action": "s3:ListBucket",
        "Resource": "arn:aws:s3:::my-bucket-with-images"
    }
]

}

And, I am able to sync data between S3 bucket and EC2 and viceversa with the following command:

aws s3 sync s3://my-bucket-with-images /var/www/images

The problem is that I don't want a manual synchronisation , I want it to automatically detect new changes in S3 and apply them to the EC2 instance directory.

I know there are several threads on this forum about using a cron to run this command every so often but I am concerned about the CPU/MEM consumption and running the command too often without having to synchronise anything most of the time.

My question is, do you know of and/or is there a cleaner alternative even using other services if it was necessary?

SOLUTION:

Finally I found the best solution, S3FS-FUSE. A tool that allows you to have a folder as a shared volume with an S3 bucket instead of synchronising manually or with a cron. https://github.com/s3fs-fuse/s3fs-fuse

S3 notifications can help you there as well https://docs.aws.amazon.com/AmazonS3/latest/userguide/NotificationHowTo.html . Its easy to subscribe and you can run the command then

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM