-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Describe the bug
This is the same as or very similar to #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 neverbundles the asset, and the stack is selected for deploy and works as expected.yarn cdk deploy "development/*" --require-approval never --exclusivelyskips 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