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.33k stars 3.76k forks source link

aws-s3-deployment: BucketDeployment cannot be used as dependency for L1 resources #30635

Open megakoresh opened 4 days ago

megakoresh commented 4 days ago

Describe the feature

We should be able to call addDepenedency(bucketDeployment) on L1 resources that depend on a bucket deployment, but it does not currently work.

Use Case

Right now, e.g. cases where an L1 resource depends on an S3 objects (such as Greengrassv2 ComponentVersions) are unsupported, as the BucketDeployment is some kind of special resource that does not implement the interfaces of the CfnResource, including also on it's node.defaultChild property. This makes it impossible to use the BucketDeployment with such resources, as they require the S3 object to already exist before they can be created.

Proposed Solution

I think node.defaultChild property of the BucketDeployment should implement CfnResource interface because its just a custom resource and those can be used as dependencies in Cloudformation, right?

Other Information

I was able to use this hack as a workaround:

const recipie = this.generateGGv2Recipie();

const depl = new BucketDeployment(this, "GGv2RunScript", {
  sources: [
    Source.asset(path.join(__dirname, "..", "..", "..", "src"), {
      ignoreMode: cdk.IgnoreMode.GIT,
      exclude: ["*", "!ggv2-run.sh"],
      assetHash: recipie,
    })
  ],
  destinationBucket: Bucket.fromBucketName(this, "ComponentsBucket", cfg.componentsBucketName),
  // its required to make sure the path to file is predictable because greengrass needs full path to the file in the recipie and the file to exist at the given location before the componentversion can be created
  destinationKeyPrefix: "/my/prefix/",
  extract: true
});

const componentVersion = new ggv2.CfnComponentVersion(this, "MyComponent", {
  inlineRecipe: recipie,
});
Dependable.implement(depl, {dependencyRoots: [depl]})
componentVersion.node.addDependency(depl)

Acknowledgements

CDK version used

2.147.0

Environment details (OS name and version, etc.)

Ubuntu 22.04, AMD64