Closed iforapsy closed 3 years ago
This is a reasonable request. Marking as feature request.
I would classify it as more of a bug since nowhere in the documentation does it state that HeaderCollection is silently discarded when uploading a folder. In fact, the docs explicitly list -HeaderCollection
as a valid argument to the UploadFolder variant of the cmdlet.
I suspect I may be having the same issue but with the Copy-S3Object cmdlet. I'm happy to open another issue but I thought maybe this might be the same thing?
Copy-S3Object -BucketName my-bucket -DestinationBucket my-bucket -Key 'index.html' -DestinationKey 'index.html' -HeaderCollection @{"Cache-Control" = "no-cache"}
Running the command actually results in an error:
Copy-S3Object : This copy request is illegal because it is trying to copy an object to itself without changing the object's metadata,
storage class, website redirect location or encryption attributes.
When modifying the destination key to a unique key results in the object being copied as expected, however the header collection, again, is being silently ignored.
I also have exactly the same use case with S3 and CloudFront and am experiencing the same bug.
PS C:> Get-AWSPowerShellVersion
AWS Tools for PowerShell Version 4.1.12.0 Copyright 2012-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Amazon Web Services SDK for .NET Core Runtime Version 3.7.0.14 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Write-S3Object
for -Folder
parameter uses TransferUtilityUploadDirectoryRequest
, which (and some related classes) does not currently have any property for specifying Headers. This is most likely a change in AWSSDK.S3
followed by Write-S3Object
CmdLet.
EDIT:
Write-S3Object
CmdLet uses UploadFolderToS3 to upload folder using the TransferUtilityUploadDirectoryRequest
. Before executing the TransferUtility.UploadDirectory()
, it executes AmazonS3Helper.SetExtraRequestFields(request, cmdletContext) to set the TransferUtilityUploadDirectoryRequest. UploadDirectoryFileRequestEvent
, which appears to execute SetMetadataAndHeaders(uploadRequest, cmdletContext.Metadata, cmdletContext.Metadata)
for each file. Notice it uses cmdletContext.Metadata
for headers as well, which could be the reason on why headers are ignored.
This is fixed in AWS.Tools.S3 4.1.13.0.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
When I try to upload a folder to a key prefix using
Write-S3Object
, the-HeaderCollection
argument seems to be silently ignored. The folder is successfully uploaded, but none of the S3 objects have the metadata headers that I specified.Expected Behavior
The files are uploaded to S3 and they have the metadata headers that I specified in the
HeaderCollection
argument.Current Behavior
The files are uploaded but without the headers that I specified.
Possible Solution
Unsure
Steps to Reproduce (for bugs)
Write-S3Object -Folder my-folder -BucketName my-bucket -KeyPrefix my-prefix/ -HeaderCollection @{'Cache-Control'='max-age=12345'}
Context
I am trying to use the
Write-S3Object
cmdlet to recursively upload a directory tree to my S3 bucket. This S3 bucket will be used as the origin for a CloudFront distribution so that is why I want to set special headers on the S3 objects, most importantly theCache-Control
header.Your Environment
I am running Windows 10 Enterprise version 1903.