aws / aws/aws-cdk

(aws_lambda_nodejs): esbuild failed because --external

Open
#30,080 6 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-lambda-nodejs bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

Running the following CDK construct:

`new aws_lambda_nodejs.NodejsFunction(this, 'RollbarNotifierLambda', {
projectRoot: path.join(__dirname, '../assets/RollbarNotifier/'),
entry: path.join(__dirname, '../assets/RollbarNotifier/index.js'),
functionName: `${envName}-rollbar-notifier`,
handler: 'index.handler',
memorySize: 1024,
runtime: lambda.Runtime.NODEJS_20_X,
timeout: Duration.seconds(300),
depsLockFilePath: path.join(__dirname, '../assets/RollbarNotifier/yarn.lock')
});`

I got:

`Error: Failed to bundle asset SodEtlStack/RollbarNotifierLambda/Code/Stage, bundle output is located at /Users/blanchma/stackwell/sod-ingestion-pipeline/sod-etl/cdk.out/bundling-temp-76055022e26f668566fb894525a4479d0199145c9f6941468063ea115c5cfab1-error: Error: bash -c yarn run esbuild --bundle "/Users/blanchma/stackwell/sod-ingestion-pipeline/sod-etl/assets/RollbarNotifier/index.js" --target=node20 --platform=node --outfile="/Users/blanchma/stackwell/sod-ingestion-pipeline/sod-etl/cdk.out/bundling-temp-76055022e26f668566fb894525a4479d0199145c9f6941468063ea115c5cfab1/index.js" --external:@aws-sdk/* run in directory /Users/blanchma/stackwell/sod-ingestion-pipeline/sod-etl/assets/RollbarNotifier/ exited with status 1`

`esbuild --version
0.20.2`

If I run the command as shown in the error without `--external:@aws-sdk/*` it works fine.

### Expected Behavior

CDK bundle and deploy the function.

### Current Behavior

The esbuild command line seems to be built incorrectly.

### Reproduction Steps

Build a function using NodeJsFunction.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.139.0

### Framework Version

_No response_

### Node.js Version

18.19.1

### OS

macos 12.7

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the NodejsFunction bundle using the reported esbuild 0.20.2 command and compare it with the same command without --external:@aws-sdk/*. Trace where the NodejsFunction bundling command is assembled, then verify that CDK can bundle and deploy the function with the intended AWS SDK externalization.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, nodejs, typescript
Domain
build-system, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.