-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(servicecatalog): support nested stacks in product stacks #26311
Conversation
Signed-off-by: Francis <colifran@amazon.com>
…is property to true when nested stack adds its template file to the parent stack Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
…te correct FileAssetLocation Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
…f not provided and will be required for imported buckets Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
…ests Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
|
||
constructor(assetBucket?: IBucket) { | ||
constructor(private readonly parentDeployment: cdk.IStackSynthesizer, private readonly assetBucket?: IBucket) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This okay in principle, but we tend to prefer props objects.
Because I have just approved an other PR that also adds stuff to this: https://github.com/aws/aws-cdk/pull/26303/files#diff-26862b8f0be4955057aed48a0d3dfabefaa27d96e95d3c5c99a3a85cc10ce770R18
Can you rebase your PR and then turn this whole thing into a prop object please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been updated. I created an interface named ProductStackSynthesizerProps
and I moved all constructor properties inside of that.
|
||
constructor(assetBucket?: IBucket) { | ||
constructor(private readonly parentDeployment: cdk.IStackSynthesizer, private readonly assetBucket?: IBucket) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor(private readonly parentDeployment: cdk.IStackSynthesizer, private readonly assetBucket?: IBucket) { | |
constructor(private readonly parentStack: cdk.Stack, private readonly assetBucket?: IBucket) { |
I know this is only an internal class, but I wonder if passing the parent stack is a bit cleaner as an API. Passing a synthesizer feels like we are implying that any synthesizer could be passed in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the code to pass the parentStack
as part of the newly added ProductStackSynthesizerProps
SourceBucketNames: cdk.Lazy.uncachedList({ produce: () => this.sources.map(source => source.bucket.bucketName) }), | ||
SourceObjectKeys: cdk.Lazy.uncachedList({ produce: () => this.sources.map(source => source.zipObjectKey) }), | ||
SourceMarkers: cdk.Lazy.uncachedAny({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure this is needed.... but why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question.
TL;DR - this is needed to ensure the nested stack template file is added as a Source
to the BucketDeployment
.
Take this code block as an example:
class SampleNestedStack extends cdk.NestedStack {
constructor(scope: Construct, id: string) {
super(scope, id);
new lambda.Function(this, 'HelloHandler1', {
runtime: lambda.Runtime.PYTHON_3_9,
code: lambda.Code.fromAsset(path.join(__dirname, 'assets')),
handler: 'index.handler',
});
new lambda.Function(this, 'HelloHandler2', {
runtime: lambda.Runtime.PYTHON_3_9,
code: lambda.Code.fromAsset(path.join(__dirname, 'assetsv2')),
handler: 'index.handler',
});
}
}
Note: I'm not a Lazy
expert, but the process is something like this. I had some help from @rix0rrr to figure this part out.
First, the Code
assets from the two lambda Functions
will be added as Sources
to the BucketDeployment
. Since these are evaluated with Lazy
they are added to a cache before evaluation is carried out. At the point when the NestedStack
is ready to add its own template, the Lazy
logic has already assumed all assets have been added to the cache. This results in the template file for NestedStack
being left out when SourceBucketNames
, SourceObjectKeys
, and SourceMarkers
is evaluated. Lazy.uncachedList
is basically saying don't only rely on the cache, there may be more items to evaluate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, probably not necessary for the markers. Doesn’t really harm, but maybe put it back? And add a comment saying that its uncached because the contents may change for nestedstacks in a productstacj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think so either, but it actually is. An error is thrown if SourceObjectKeys
length isn't equal to SourceMarkers
length and it'll be off by 1 if List.any
is used.
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
7035135
to
b1a4ef3
Compare
Signed-off-by: Francis <colifran@amazon.com>
…s interface Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Signed-off-by: Francis <colifran@amazon.com>
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This PR fixes a bug that prevented a nested stack from being used within a product stack. The logic in the `addFileAsset` method as part of the `ProductStackSynthesizer` was updated to forward all assets to the parent stack and uses the `FileAssetLocation` returned from the parent stack synthesizer to create a bucket `Source` from the `bucketName` and `objectKey`. Closes aws#24317 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This PR fixes a bug that prevented a nested stack from being used within a product stack. The logic in the
addFileAsset
method as part of theProductStackSynthesizer
was updated to forward all assets to the parent stack and uses theFileAssetLocation
returned from the parent stack synthesizer to create a bucketSource
from thebucketName
andobjectKey
.Closes #24317
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license