Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 如何使用S3、CloudFront和Write-S3Object缓存1分钟_Amazon Web Services_Amazon S3_Amazon Cloudfront_Cache Control_Aws Powershell - Fatal编程技术网

Amazon web services 如何使用S3、CloudFront和Write-S3Object缓存1分钟

Amazon web services 如何使用S3、CloudFront和Write-S3Object缓存1分钟,amazon-web-services,amazon-s3,amazon-cloudfront,cache-control,aws-powershell,Amazon Web Services,Amazon S3,Amazon Cloudfront,Cache Control,Aws Powershell,我有一个来自S3的临时CloudFront站点 我想做的是将其设置为Cloudfront只缓存一分钟,之后的任何请求都将返回到S3以获取新数据。如果可能的话,我也想知道如何完全关闭缓存 我试过这个: Write-S3Object -BucketName "xx-staging" -Key "index.html" -Metadata @{"Cache-Control" = "60000"} -File

我有一个来自S3的临时CloudFront站点

我想做的是将其设置为Cloudfront只缓存一分钟,之后的任何请求都将返回到S3以获取新数据。如果可能的话,我也想知道如何完全关闭缓存

我试过这个:

Write-S3Object -BucketName "xx-staging" 
               -Key "index.html" 
               -Metadata @{"Cache-Control" = "60000"}
               -File "index.html" 
结果是:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 24686
Connection: keep-alive
Date: Mon, 18 May 2015 14:14:21 GMT
x-amz-meta-cache-control: 60000
Last-Modified: Mon, 18 May 2015 13:45:46 GMT
ETag: "b2d38663e20237e056f8e507a2caa77a"
Accept-Ranges: bytes
Server: AmazonS3
Age: 1648
X-Cache: Hit from cloudfront
Via: 1.1 6d4df30b39d1e7ecggb0ecd7b8940b88.cloudfront.net (CloudFront)
X-Amz-Cf-Id: oNHGs5CK8hed2OJ_BPaeaf1zFzQE4w7tmnkOym5_1QAMvU6YjNwcfw==
五分钟后,当我尝试另一个请求时,我得到了与之类似的答复

X-Cache: Hit from cloudfront
谁能指出我做错了什么

请注意,我正在寻找使用Write-S3Object的答案

请注意,我尝试在门户中添加:

CacheControl最大年龄:60000

这给了我以下仍然说“从云端击中”

。您需要标题看起来像这样*:

Cache-Control: public,max-age=60
Cache-Control: no-cache
缓存控制标头使用秒,而不是毫秒。”“public”的基本意思是“可以将其存储在CDN上”。我相信这将在您最初的Powershell命令中起作用:

 -HeaderCollection @{"Cache-Control" = "public,max-age=60"}
如果要完全禁用缓存,请按以下方式设置*:

Cache-Control: public,max-age=60
Cache-Control: no-cache
或者这个:

Cache-Control: max-age=60,must-revalidate
我建议使用
curl-d-http://s3-website-url
以测试您的操作是否正确。这样,您就可以忘记Cloudfront来验证标头


*
有很多变化。这是一种非常常见的方法,会起作用。

非常感谢您的提示和提示。我愚蠢的错误。我尝试了你的建议,但使用-Metadata只设置:x-amz-meta-cache-control:public,max age=60,这似乎没有任何作用。啊,对@Melina,它不是元数据头。