Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws_s3_deployment): Specify destinationKey for S3 asset in BucketDeployment #30846

Closed
1 of 2 tasks
erwaxler opened this issue Jul 12, 2024 · 5 comments
Closed
1 of 2 tasks
Labels
@aws-cdk/aws-s3-deployment effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p3

Comments

@erwaxler
Copy link

Describe the feature

I am proposing that an optional prop destinationKey is added to the BucketDeployment construct, mirroring the destinationKey prop that exists on the DeployTimeSubstitutedFile construct. This will allow users to upload file assets to S3 to a predefined S3 path.

Use Case

I am trying to use the CDK to create and invoke an AWS CodePipeline that uses S3 as a source. CodePipeline requires that files exist as a .zip file in the source S3 bucket. While I know I could reference the auto-generated object key of the file in the CodePipeline definition, this would then require users to reuse a lengthy and meaningless file name when working with files locally, rather than a friendly expected name.

I attempted to use DeployTimeSubstitutedFile to achieve this behavior with a locally zipped file (with no substitutions), but this resulted in a corrupted zip file in S3.

Proposed Solution

Add an optional destinationKey similar to what was done for the DeployTimeSubstitutedFile class here: #29029

Other Information

I understand this feature represents a general anti-pattern in CDK of using static names, in this use case the idea is to generate an easy-to-use CodePipeline for users who likely do not have significant development experience. I'm open to other ideas of how to work around this that result in local files zipped and uploaded to S3 with a specific object key that don't require implementing a custom resource.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.147.3

Environment details (OS name and version, etc.)

macOS Sonoma 14.5

@erwaxler erwaxler added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 12, 2024
@erwaxler erwaxler changed the title (aws_s3_deployment): (short issue description) (aws_s3_deployment): Specify destinationKey for S3 asset during S3BucketDeployment Jul 12, 2024
@erwaxler erwaxler changed the title (aws_s3_deployment): Specify destinationKey for S3 asset during S3BucketDeployment (aws_s3_deployment): Specify destinationKey for S3 asset in BucketDeployment Jul 12, 2024
@ashishdhingra
Copy link
Contributor

BucketDeployment construct also supports optional destinationKeyPrefix property. So it needs to be decided whether to use it as prefix or ignore it, if we happen to support destinationKey property.

@ashishdhingra ashishdhingra added p2 effort/medium Medium work item – several days of effort p3 and removed needs-triage This issue or PR still needs to be triaged. p2 labels Jul 12, 2024
@erwaxler
Copy link
Author

@ashishdhingra That's a great point, I would personally lean toward validating that only one of destinationKeyPrefix or destinationKey is specified.

After some more thought,destinationKey would also not be relevant when using BucketDeployment to upload multiple files. Allowing for a destinationKey property may require validating that when specified, sources contains a single file (difficult) or that the extract property is set to false (easier).

@erwaxler
Copy link
Author

I've discovered I can achieve this by specifying the asset path to be the directory containing the .zip file rather than the full file path. I'll be closing this issue as this discovery negates the need for a destinationKey property from my perspective.

For anyone attempting to upload a zip file using BucketDeployment:

Works:

    new cdk.aws_s3_deployment.BucketDeployment(this, 'UploadZipFileToS3', {
      sources: [cdk.aws_s3_deployment.Source.asset(`zipFileDirectory`)],

Does not work:

    new cdk.aws_s3_deployment.BucketDeployment(this, 'UploadZipFileToS3', {
      sources: [cdk.aws_s3_deployment.Source.asset(`zipFileDirectory/zipFile.zip`)],

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

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.

@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-s3-deployment effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p3
Projects
None yet
Development

No branches or pull requests

3 participants