-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
(aws-cdk): asset bundling skipped when using --exclusively option #12898
Comments
I couldn't reproduce it. The bundle runs without problems. I would appreciate it if you could share the detailed settings. |
@hedrall Sorry, my bad. I forgot one important detail - it only happens when using nested stacks. Here is a small reproduce: #!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import { CdkStack } from '../lib/cdk-stack';
const app = new cdk.App();
new CdkStack(app, 'CdkStack'); import * as cdk from '@aws-cdk/core';
import { Bundling } from "@aws-cdk/aws-lambda-nodejs/lib/bundling";
import * as synthetics from '@aws-cdk/aws-synthetics';
import * as lambda from '@aws-cdk/aws-lambda';
import { join } from 'path';
export class CdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new NestedStack(this, "NestedStack");
}
}
class NestedStack extends cdk.NestedStack {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
new synthetics.Canary(this, "Canary", {
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_0,
schedule: synthetics.Schedule.rate(cdk.Duration.minutes(30)),
test: synthetics.Test.custom({
handler: "index.handler",
code: Bundling.bundle({
depsLockFilePath: join(__dirname, "js"),
entry: join(__dirname, "js", "index.js"),
runtime: lambda.Runtime.NODEJS_12_X,
forceDockerBundling: true,
minify: true,
}),
}),
});
}
} Doing a |
I stumbled into this when using a simple PythonFunction construct (no nested stacks). |
This is a massive issue and it's a nasty one! @miekassu and I have have spent 10+ hours on debugging this issue. @miekassu has created a repro here: https://github.com/miekassu/lambda-build-fail To test it: git clone https://github.com/miekassu/lambda-build-fail.git
cd lambda-build-fail
npm i
cdk deploy -e 'Stage/Stack' During the deployment you'll not see any errors, but the publishing step may take a minute, because the bundle is large This part:
Then you can try:
And observe that the directory is unreasonable large. You can also inspect the S3 bucket and see the asset that was uploaded and it will be ~ 70 MB, I think. What happens is that not that asset bundling just gets skipped. That wouldn't be too bad. But in reality, what happens is that, somehow, the asset for each lambda becomes the entire project directory ( This, of course fails completely with:
Another observation. When running |
It looks like on that line that @supaiku0 specified (minimatch), the value of |
But if It just cleanly exits 🤷🏼♂️
|
I added more stacks and lambdas to the example repository. Produces not wanted Lambda asset path pointing to the root folder of the project:
Targeting manifest in
Using
This known issue is preventing the usage of new |
Can confirm this bug still exists with the -e flag.
My suspicion is, that the CDK version: 1.123.0 What's the alternative/workaround? |
@miekassu what do you mean with asset path pointing to the root folder? Where do you see this? |
@jogold in example repo running
and running
|
…r stage (#17210) We were comparing bundling stacks of the form `Stage/Stack` with stack names of the form `Stage-Stack`. For stacks with `NodejsFunction`s this leads to assets containing the whole CDK project because when bundling is skipped the asset references the source directory which is the project root. Closes #12898 Closes #15346 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
…r stage (aws#17210) We were comparing bundling stacks of the form `Stage/Stack` with stack names of the form `Stage-Stack`. For stacks with `NodejsFunction`s this leads to assets containing the whole CDK project because when bundling is skipped the asset references the source directory which is the project root. Closes aws#12898 Closes aws#15346 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…r stage (aws#17210) We were comparing bundling stacks of the form `Stage/Stack` with stack names of the form `Stage-Stack`. For stacks with `NodejsFunction`s this leads to assets containing the whole CDK project because when bundling is skipped the asset references the source directory which is the project root. Closes aws#12898 Closes aws#15346 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
A workaround I found was doing the following within my stack, not exactly thrilled to be doing this but it has helped me avoid more drastic workarounds. export class NodeLambdaConsumer extends NestedStack {
public readonly lambda: lambda.Function;
constructor(
scope: Construct,
id: string,
{
...
}: NodeLambdaConsumerProps,
) {
super(scope, id, {});
// mutate the BUNDLING_STACKS config in ctx
const config = this.node.getContext(BUNDLING_STACKS);
config.push(this.node.path); Something I was also considering was just replacing |
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.aws-cdk/packages/@aws-cdk/core/lib/asset-staging.ts
Line 164 in 9417b02
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:Tested on Linux and Windows and CDK 1.88.
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: