question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-cdk): asset bundling skipped when using --exclusively with custom stack name

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Reactions:23
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
corymhallcommented, Apr 18, 2022

@stevehodgkiss it looks like you have a PR to fix this. Someone from the team should pick up the PR to review.

0reactions
github-actions[bot]commented, Oct 10, 2022

⚠️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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting common AWS CDK issues
When deploying my AWS CDK stack, I receive a NoSuchBucket error ... a locally installed AWS CDK Toolkit, use the command npx aws-cdk...
Read more >
AWS CDK assets docker bundling - Stack Overflow
When bundling artifacts CDK hashes the files in the artifact, if the hash doesn't match then it believes changes have been made and ......
Read more >
AWS CDK Toolkit - npm
By default asset bundling is skipped for cdk list and cdk destroy . For cdk deploy , cdk diff and cdk synthesize the...
Read more >
AWS CDK - Fullstack Polyglot with Asset Bundling
This will save enormous amounts of time on larger stacks. I've covered use cases for TypeScript applications in Lambda and S3 websites in...
Read more >
5 Ways To Bundle a Lambda Function Within an AWS CDK ...
Have you ever tried to publish a CDK construct that was using a Lambda function, for example to create a custom resource or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found