[英]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.我创建了一个没有公共访问权限的 S3 存储桶,以便充当具有 EC2 实例目录的共享文件夹。
I have assigned a role with a policy to the EC2 instance in order to be able to synchronise data with each other.我已经为 EC2 实例分配了一个具有策略的角色,以便能够相互同步数据。
{
"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:而且,我可以使用以下命令在 S3 存储桶和 EC2 之间同步数据,反之亦然:
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.问题是我不想手动同步,我希望它自动检测 S3 中的新更改并将它们应用到 EC2 实例目录。
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.我知道这个论坛上有几个线程经常使用 cron 来运行这个命令,但我担心 CPU/MEM 消耗和过于频繁地运行命令而不必在大多数时间同步任何东西。
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.最后我找到了最好的解决方案,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.
一种工具,可让您将文件夹作为与 S3 存储桶的共享卷,而不是手动或使用 cron 进行同步。 https://github.com/s3fs-fuse/s3fs-fuse
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 . S3 通知也可以帮助您https://docs.aws.amazon.com/AmazonS3/latest/userguide/NotificationHowTo.html 。 Its easy to subscribe and you can run the command then
它很容易订阅,然后您可以运行命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.