Skip to content

(core/aws-lambda-nodejs/cli): confusing NodejsFunction+Stage+exclusive-cli-flag behaviour #15346

@plumdog

Description

@plumdog

When deploying using all of the following, the asset for the Lambda function is a zip of the root of the project, not the asset as expected:

  • a stack containing a @aws-cdk/aws-lambda-nodejs.NodejsFunction Lambda function
  • attaching the stack I'm deploying to a @aws-cdk/core.Stage rather than to a @aws-cdk/core.App
  • using the -e (exclusive) flag to the synth or deploy commands

Based on my testing, not doing any one of these things results in the expected behaviour where the asset is the expected thing.

See dummy project here https://github.com/isotoma/cdk-nodejsfunction-asset-size-debugging to show my testing and why I have ended up where I have.

I happened to find this because a real project uploaded the whole project root as the source asset for the Lambda, which ended up being over Lambda's 250MB limit.

Reproduction Steps

See https://github.com/isotoma/cdk-nodejsfunction-asset-size-debugging, and the branches listed in the readme, and the behaviour shown in the Github CI.

What did you expect to happen?

  • Use of the -e CLI flag should not affect the built asset
  • Use of a Stage should not affect the built asset

What actually happened?

  • I would not expect the whole project directory to ever be zipped and uploaded to the assets bucket.

Environment

  • CDK CLI Version : 1.110.1 (also affects >= 1.102.0, because that's where the feature to deploy stacks from stages arrived, see feat(cli): directly deploy stacks in nested assemblies #14379. Believe earlier versions did not have this feature.)
  • Framework Version: 1.110.1
  • Node.js Version: v14.17.0
  • OS: Linux
  • Language (Version): Typescript 4

Other

I am mildly suspicious of switches in context in cdk.json, but for no real reason, and have no guesses as to what might actually be wrong.

Happy to try other things with my dummy project if useful.


This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions