Home > Software engineering >  AWS EC2 shared folder with S3 without manual sync
AWS EC2 shared folder with S3 without manual sync

Time:10-11

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?

CodePudding user response:

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

CodePudding user response:

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

  • Related