How to include aws-sdk v3 packages so they are not included in the production bundle?

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, 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” ? I tried with optional and peer dependencies, nothing change.

Solved. The problem:

  • I was using serverless-bundle and didn’t realize it excludes aws-sdk (the v2) by default
  • But doesn’t do it for v3 (probably because of modular packages), so one has to manually list all packages from aws-sdk v3 that one wants to exclude.