Lambda can't find modules from outer folders when deployed with CDK

If your lambda function uses dependencies, you'll have to package everything into a ZIP file and tell CDK where to find the ZIP. It will then upload it for you to S3. But the packaging will be your responsibility. You need to include all the dependencies as well as your code.

CDK currently supports 3 kinds of "Assets":

  • InlineCode - useful for one-line-lambdas
  • AssetCode - one-file lambdas without dependencies
  • S3Code - existing lambda packages already uploaded in an S3 bucket

For your use-case, you'll need AssetCode, but instead of a directory, you'll point to local ZIP file.

Related answer: How to install dependencies of lambda functions upon cdk build with AWS CDK

Since quite a few people ask about this, I'll see if I can open-source my lambda packaging construct in Python. If yes, I'll link it here.

Edit: I opensourced a CDK construct which I use for lambda packaging with more than a hundred dependencies including NumPy.

https://gitlab.com/josef.stach/aws-cdk-lambda-asset