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 option

See original GitHub issue

Asset bundling is currently broken when using the --exclusively option during deploy.

In our case we have an aws-lambda-nodejs with forceDockerBuild set to true (but it shouldn’t matter).

However, due to the following check the bundling never happens when e.g. running cdk deploy --exclusively 'MyStack' - as in it will skip the bundling step completely.

Concretely, this minimatch evaluates to false for any given stack name, except when using --all which evaluates to the wildcard * satisfying anything. https://github.com/aws/aws-cdk/blob/9417b0211eb2939f5a853751333f7941d9dd99f8/packages/%40aws-cdk/core/lib/asset-staging.ts#L164

That is because Stack.of(this).stackName is not resolved at this point. The screenshot shows the output of running with --all (bundlingStacks contains [*]) against the unresolved stack name:

image

Tested on Linux and Windows and CDK 1.88.


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
miekassucommented, Sep 27, 2021

I added more stacks and lambdas to the example repository. Some of my observations while debugging:

Produces not wanted Lambda asset path pointing to the root folder of the project:

 cdk diff -e Stage/Stack1

Targeting manifest in cdk.out/assembly folder produces right asset path when using -e tag. To update templates, I used synth commands, which then also bundles other lambdas in the other stacks during synth, this is unwanted and in large projects takes a lot of time.

 cdk synth && cdk -a cdk.out/assembly-Stage diff -e Stage/Stack1

Using -e tag with synth commands only bundles lambdas from wanted stack, but it also points lambda asset path to project root.

 cdk synth -e Stage/Stack1 && cdk -a cdk.out/assembly-Stage diff -e Stage/Stack1

This known issue is preventing the usage of new --hotswap feature with multi stack projects.

1reaction
michaelfechercommented, Oct 12, 2021

Can confirm this bug still exists with the -e flag. I have a similar setup with multiple stacks. The entry for the NodeJsFunction is the default one, aka

- Derived from the name of the defining file and the construct's id.
If the `NodejsFunction` is defined in `stack.ts` with `my-handler` as id
(`new NodejsFunction(this, 'my-handler')`), the construct will look at `stack.my-handler.ts`
and `stack.my-handler.js`.

My suspicion is, that the cdk deploy -e stackName internally has a wrong context and therefore adds the root of the project as the asset.

CDK version: 1.123.0

What’s the alternative/workaround?

Read more comments on GitHub >

github_iconTop Results From Across the Web

(aws-cdk): asset bundling skipped when using --exclusively ...
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...
Read more >
Troubleshooting common AWS CDK issues
This topic describes how to troubleshoot the following issues with the AWS CDK.
Read more >
AWS CDK - Fullstack Polyglot with Asset Bundling
This is my third article that deals with asset bundling in AWS ... We can tell CDK how to diff our output, thereby...
Read more >
@aws-cdk/aws-s3-assets - npm
When deploying a CDK app that includes constructs with assets, the CDK toolkit will first upload all the assets to S3, and only...
Read more >
5 Ways To Bundle a Lambda Function Within an AWS CDK ...
The problem is that if you require other dependencies in an AWS Lambda function, you need to bundle them with your function (the...
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