(aws-cdk): asset bundling skipped when using --exclusively with custom stack name
See original GitHub issueDescribe the bug
This is the same as or very similar to https://github.com/aws/aws-cdk/issues/12898.
# cdk ls --long
- id: development/CdkBundlingIssueStack
name: CustomStackName
environment:
account: unknown-account
region: unknown-region
name: aws://unknown-account/unknown-region
When using a custom stack name, a stage and cdk deploy "development/*" --exclusively
:
- asset bundling is skipped.
- on deploy, the entire repo is bundled into a zip file and uploaded.
Expected Behavior
Asset bundling shouldn’t be incorrectly skipped.
There’s a separate issue of if it is skipped, the entire repo shouldn’t be bundled into a zip file and uploaded.
Current Behavior
Asset bundling is skipped, then the entire repo is uploaded instead of the zip file.
Reproduction Steps
CDK App:
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { Stage } from 'aws-cdk-lib';
import { Stack, StackProps } from 'aws-cdk-lib';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { Construct } from 'constructs';
class CdkBundlingIssueStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new NodejsFunction(this, 'lambda', {})
}
}
class MyStage extends Stage {
constructor(scope: Construct, id: string) {
super(scope, id)
new CdkBundlingIssueStack(this, 'CdkBundlingIssueStack', {
stackName: 'CustomStackName'
});
}
}
const app = new cdk.App();
new MyStage(app, 'development')
# cdk ls --long
- id: development/CdkBundlingIssueStack
name: CustomStackName
environment:
account: unknown-account
region: unknown-region
name: aws://unknown-account/unknown-region
yarn cdk deploy "development/*" --require-approval never
bundles the asset, and the stack is selected for deploy and works as expected.yarn cdk deploy "development/*" --require-approval never --exclusively
skips bundling, bundles the entire repo into an assets zip file instead of the lambda.
Possible Solution
I think the issue is the pattern is matched against stackName in @aws-cdk/core to determine whether to bundle assets, whereas it’s matched against hierarchicalId in aws-cdk to get the list of stacks to deploy. That’s how bundling is skipped yet a deploy still happens. heirarchicalId
is the stack logical name (development/CdkBundlingIssueStack
), whereas stackName in this case is CustomStackName
.
I think the fix is to use hierarchicalId
in @aws-cdk/core
to make the pattern matching consistent.
Additional Information/Context
No response
CDK CLI Version
2.20.0
Framework Version
No response
Node.js Version
16.14.2
OS
MacOS
Language
Typescript
Language Version
No response
Other information
Relevant log lines with --verbose
show the entire repo being bundled and uploaded, instead of the zip file. This is after asset bundling is skipped when it shouldn’t be:
[0%] check: Check s3://cdk-hnb659fds-assets-12345-us-east-1/5606a614b8f65f4011c41e902adde89ca8048b8e2208efbefbb5645c64ac40d5.zip
[0%] upload: Upload s3://cdk-hnb659fds-assets-12345-us-east-1/69247885b0bf9b5b79e602c4c09ccc4c69154bdf35e933d24991cdcced8fb5ab.json
[0%] build: Zip /Users/steve/src/cdk-bundling-issue -> /Users/steve/src/cdk-bundling-issue/cdk.out/assembly-development/.cache/5606a614b8f65f4011c41e902adde89ca8048b8e2208efbefbb5645c64ac40d5.zip
Issue Analytics
- State:
- Created a year ago
- Reactions:23
- Comments:9 (5 by maintainers)
@stevehodgkiss it looks like you have a PR to fix this. Someone from the team should pick up the PR to review.
⚠️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.