如何使用带有S3和Cloudfront分发的Write-S3Object设置缓存控制?

6 amazon-s3

我一直这样做,但现在它似乎不再起作用(2015年8月):

Write-S3Object -BucketName "example-bucket" 
   -KeyPrefix "app/admin/partials" 
   -Folder 'app/admin/partials' -SearchPattern '*.html' 
   -HeaderCollection @{"Cache-Control" = "public,max-age=120"}
Run Code Online (Sandbox Code Playgroud)

最近发生了什么变化?当我在S3中检查时,没有设置头信息.

Dan*_*anH 0

您需要在查询中使用-Metadata-HeaderCollection @{"Cache-Control" = "public,max-age=120"}参数,更改参数才能-Metadata @{"Cache-Control" = "public,max-age=120"}正常工作,并且可以在 AWS Web 控制台中看到。

这是工作片段

 Write-S3Object -BucketName myBucket -file "test.json" -Metadata
 @{"Cache-Control" = "public,max-age=120"}
Run Code Online (Sandbox Code Playgroud)

这是使用以下版本的 Powershell 运行的。

PS C:\Users\DanielH1> Get-AWSPowerShellVersion

AWS Tools for Windows PowerShell
Version 3.1.5.1
Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Amazon Web Services SDK for .NET
Version 3.1.0.2
Copyright 2009-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Release notes: https://aws.amazon.com/releasenotes/PowerShell

This software includes third party software subject to the following copyrights:
- Logging from log4net, Apache License
[http://logging.apache.org/log4net/license.html]
Run Code Online (Sandbox Code Playgroud)

以下是供参考的文档链接: http://docs.aws.amazon.com/powershell/latest/reference/items/Write-S3Object.html