-
Notifications
You must be signed in to change notification settings - Fork 4k
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
core: incorrect asset bundling skip for assets in stacks inside stages inside stacks #21925
Comments
i have the same problem how to fix this? |
I found that putting public override get bundlingRequired() {
return true;
} in the stack class that directly contains the Lambda resulted in the correct behaviour, though will mean bundling sometimes happens unnecessarily. |
Could you clarify what error message you're getting (it's an error on deploy that the zipfile is too big for the lambda?), plus could you share reproduction steps (are you using just a |
@peterwoodworth the behaviour only occurs when CDK is trying to work out which stacks need bundling and which don't, which I think is only when deploying with the
When those three things occur:
Thinking about it further, I think it will also fail in the 2 layers case (so just Stage -> Stack -> NodejsFunction) if the stack's name is not the default. I'll try to provide a way of replicating or a failing test. |
Thanks for the further explanation, it's a big help 🙂 |
Extra realisation that I'll check when I can: I think the cause is that These just happen to often be the same. A stack name defaults to the id, which is also the path when there's no stages. And a stack in a stage defaults to stage-stack, which is why the Assuming I'm on the right track, I think I can write a few failing tests, and I think the fix will be to compare with the stack's logical path instead of |
Is there any progress on this? Not being able to use the --exclusively flag is quite annoying when working on a project with many stacks. |
Looks like the fix for this has been merged. Closing. |
|
Describe the bug
Eg when you have:
If I try to deploy just the DeploymentStack with
npm run -- cdk deploy -e pipeline-stack/deployment-stage/deployment-stack
, the asset forSomeLambda
is not bundled. Instead, I just get the whole repo, and Lambda complains about the zip being too big.I think this might be because of this line here: https://github.com/aws/aws-cdk/blob/v1-main/packages/@aws-cdk/core/lib/stack.ts#L1179
Perhaps thatThis is half right..replace
should instead act on the last occurrence in the string, not the first.this.stackName
isdeployment-stage-deployment-stack
, butbundlingStacks
fromcxapi.BUNDLING_STACKS
ispipeline-stack/deployment-stage/deployment-stack
. So to get the correct behaviour need to munge pattern as follows:/
with a-
/
But this feels - in general - unsafe. Why are
cxapi.BUNDLING_STACKS
andthis.stackName
in different formats and what is a valid way of comparing them?The above would match with some crude debugging I bodged into my project where I encountered this, and with the comment there "bundlingStacks is of the form
Stage/Stack
, convert it toStage-Stack
before comparing to stack name": if I overridebundlingRequired
in my stack and print out whatthis.node.tryGetContext(cxapi.BUNDLING_STACKS) ?? ['*']
is, I get['pipeline-stack/deployment-stage/deployment-stack']
, butthis.stackName
is'deployment-stage-deployment-stack'
.So when the first
/
is replaced and theminimatch
comparison occurs, the match fails, because it was the first/
that was replaced.If it was the last, then it would match.(false, see above)Expected Behavior
The asset for the stack I am deployed to be bundled.
Current Behavior
The project root is zipped as the asset.
Reproduction Steps
I'm in the process of trying to write a failing test, but am fighting
buildup
atm.The test I'm trying to write looks just like the test added in cda6601 but with an extra layer of nesting, like
Stack1/Stage/Stack2
.Possible Solution
In
Stack.bundlingRequired
, replace the last/
inpattern
, not the first.Additional Information/Context
I think this is related to #15346
CDK CLI Version
2.35.0
Framework Version
No response
Node.js Version
16
OS
Linux
Language
Typescript
Language Version
No response
Other information
My workaround is to put:
in the
Stack
that contains the asset. This results in the expected behaviour.The text was updated successfully, but these errors were encountered: