设置缓存控制整个S3存储自动(使用桶政策?)缓存、政策

由网友(韩大爷@)分享简介:我需要设置缓存控制标题为整个S3桶,现有的和未来的文件,并希望能做到这一点的水桶政策。我知道我可以编辑现有的,我知道如何指定他们放,如果我上传他们自己,但不幸的上传他们的应用程序无法设置的头,因为它使用s3fs复制的文件存在。I need to set cache-control headers for an en...

我需要设置缓存控制标题为整个S3桶,现有的和未来的文件,并希望能做到这一点的水桶政策。 我知道我可以编辑现有的,我知道如何指定他们放,如果我上传他们自己,但不幸的上传他们的应用程序无法设置的头,因为它使用s3fs复制的文件存在。

I need to set cache-control headers for an entire s3 bucket, both existing and future files and was hoping to do it in a bucket policy. I know I can edit the existing ones and I know how to specify them on put if I upload them myself but unfortunately the app that uploads them cannot set the headers as it uses s3fs to copy the files there.

推荐答案

据我所知斗的政策,仍然是一个没有去,但我想通了如何使用AWS-CLI做到这一点,它是pretty的光滑。当研究我找不到在野外任何的例子,所以我想我会发表我的一些解决方案,帮助有需要的人。

As far as I know bucket policies, are still a no go, but I figured how to do it using aws-cli, and it is pretty slick. When researching I couldn't find any examples in the wild, so I thought I would post some of my solutions to help those in need.

注意:默认情况下,AWS-CLI只复制文件的当前元数据,即使指定了新的元数据

要使用命令行上指定的元数据,你需要添加--metadata-指令替换标志。这里有一些例子

To use the metadata that is specified on the command line, you need to add the '--metadata-directive REPLACE' flag. Here are a some examples.

对于单个文件的

aws s3 cp s3://mybucket/file.txt s3://mybucket/file.txt --metadata-directive REPLACE 
--expires 2034-01-01T00:00:00Z --acl public-read --cache-control max-age=2592000,public

对于整个​​桶(注意--recursive标志):的

aws s3 cp s3://mybucket/ s3://mybucket/ --recursive --metadata-directive REPLACE 
--expires 2034-01-01T00:00:00Z --acl public-read --cache-control max-age=2592000,public

一个小疑难杂症,我发现,如果你只是想将它应用到特定的文件类型,你需要排除的所有文件,然后包括你想要的人。

A little gotcha I found, if you only want to apply it to a specific file type, you need to exclude all the files, then include the ones you want.

只有JPG格式和PNG格式:的

aws s3 cp s3://mybucket/ s3://mybucket/ --exclude "*" --include "*.jpg" --include "*.png" 
--recursive --metadata-directive REPLACE --expires 2034-01-01T00:00:00Z --acl public-read 
--cache-control max-age=2592000,public

下面是一些链接到手册,如果你需要更多的信息:

Here are some links to the manual if you need more info:

HTTP://docs.aws.amazon。 COM / CLI /最新/ userguide /使用-S3-commands.html HTTP://docs.aws.amazon。 COM / CLI /最新/参考/ S3 / cp.html#选项 http://docs.aws.amazon.com/cli/latest/userguide/using-s3-commands.html http://docs.aws.amazon.com/cli/latest/reference/s3/cp.html#options

希望它能帮助!

阅读全文

相关推荐

最新文章