Custom headers on Amazon S3

最后都变了- 提交于 2019-12-30 16:26:08

问题


Is it possible to have custom headers on Amazon S3 with arbitrary naming?

For example, I am using a CDN pointing to Amazon S3 as the origin server, and in order to enable advanced functionality on the CDN I need to use a custom header "x-something-something"...

I see it's possible to do this with "x-amz-meta-(something)" but what about something more general like "x-(something)-(something)" without the amz?


回答1:


I don't think it is possible with their current API. They cover the major headers you will need for caching and browser interoperability.

I think they are being safe in only allowing x-amz-meta- prefixed custom headers, possibly to keep from clashing with user selected headers when they update their api in the future.

If you need custom attributes attached to your objects, it should be trivial to parse out the x-amz-meta- in your client application.




回答2:


This beautiful article explains it all https://medium.com/@tom.cook/edge-lambda-cloudfront-custom-headers-3d134a2c18a2

tldr:

You can't-do only with s3. You need to use Cloudfront and lambda via Lambda@Edge. It's a integration between Lambda and CloudFront. It allows you to run Lambdas within the CloudFront. This allows you to change headers among other things. So if you are ok accessing your s3 via CloudFront then this could be a viable option.




回答3:


I was able to achieve this using the s3cmd tool. I wrote a sync script that syncs my static site using the --cache-control parameter on the AWS client tool and then manually resets it and adds a couple other headers for a few specific files:

cd /appropriatedirectory

# Delete current site
aws s3 rm s3://yourbucket --recursive --exclude 'logs/*'

# Upload new site, setting cache header to 1 month for all files
aws s3 sync . s3://yourbucket --exclude '.idea/*' --exclude '.git/*' --exclude '.gitignore' --cache-control max-age=2592000

# Overrides the cache headers for some file
python /pathToS3cmd/s3cmd modify --add-header="Cache-Control:no-cache,no-store,must-revalidate" s3://yourbucket/somefile.html
python /pathToS3cmd/s3cmd/s3cmd modify --add-header="Expires:0" s3://yourbucket/somefile.html
python /pathToS3cmd/s3cmd/s3cmd modify --add-header="Pragma:no-cache" s3://yourbucket/somefile.html



来源:https://stackoverflow.com/questions/8916929/custom-headers-on-amazon-s3

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