Lambda size increase with AWS-SDK v3

In Serverless v2 with Node 14/16 and aws-sdk v2 I was including the package in devDependencies in package.json. In production aws-sdk was not including in final compiled bundle (perfect because is including in the runtime).

Note: I use the command serverless package

In Serverless v3 with Node 18 and aws-sdk v3, the packages in devDependencies are included in production bundle (I saw them in sourcemap) ! Which multiplied by 5 the size of my lambdas.

Anyone knows “the trick” please? I tried with optional and peer dependencies, nothing change.

Solved: I didn’t notice it was serverless-bundle who was excluding aws-sdk from bundle until Node.js 18 runtime.

The only solution is to list all the packages used:

custom:
  bundle:
    forceExclude:
      - "@aws-sdk/client-s3"
      - "@aws-sdk/client-dynamodb"

Here is the issue I opened with a PR :

1 Like