aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.6k stars 3.9k forks source link

aws-s3-deployment: Conditional BucketDeployment #28602

Open vs-amzn opened 9 months ago

vs-amzn commented 9 months ago

Describe the feature

Similar to how we can use a CfnCondition for s3.Bucket creation, was thinking this could be a good use case for BucketDeployment as well. Basically pass in an additional param condition: CfnCondition and depending on the condition, the assets will/will not be deployed to the bucket.

Use Case

Originally would like to conditionally deploy based off of what's currently deployed in s3 (ex] if object[x] === true, don't deploy. else deploy). So was thinking of using CfnOutputs and was trying to conditionally deploy to s3 based on the value of CfnOutput in a separate stack but it seems like this is not possible.

Proposed Solution

No response

Other Information

No response

Acknowledgements

CDK version used

2.60.0

Environment details (OS name and version, etc.)

NodeJS 18, Typescript

vs-amzn commented 9 months ago

Was thinking of creating a CfnCustomResource (which is of type CfnResource and inherently has the cfnOptions.condition property). This would be a wrapper to create a BucketDeployment. So if the cfnOptions.condition evaluates to false, the CfnCustomResource wouldn't be deployed and in turn the BucketDeployment wouldn't deploy either. If true, it would deploy an update.

pahud commented 9 months ago

I am not sure if it's a good idea to expose that property in the L2 but you can always do that by yourself by finding the L1 resource and override the its condition property.

vs-amzn commented 9 months ago

Would CfnCustomResource be considered an L1 resource?