3

I've been experimenting with using the new AWS CDK pipelines construct (https://docs.aws.amazon.com/cdk/api/latest/docs/pipelines-readme.html), and have successfully setup a couple of projects, including following the blog post announcement here: https://aws.amazon.com/blogs/developer/cdk-pipelines-continuous-delivery-for-aws-cdk-applications/.

However, as soon as I try to add a dependency to my lambdas the build fails with a

lib/lambda/handler.ts(2,24): error TS2307: Cannot find module 'stripe' or its corresponding type declarations.

I have installed a package.json file and the node_modules in the directory with the lambdas, tried zipping the lambdas and node_modules, tried uploading the zip file with the console, and tried getting the 'buildCommand' during the 'synthAction' step to install the dependencies. Nothing works.

The asset appears to get created in the cdk.out directory, and code changes are being uploaded, but node_modules themselves never get packaged along with the lambda functions.

I am using the 'SimpleSynthAction.standardNpmSynth' action, along with an 'npm run build' command in the 'buildCommand' step.

I've looked at Lambda can't find modules from outer folders when deployed with CDK, How to install dependencies of lambda functions upon cdk build with AWS CDK and https://github.com/aws-samples/aws-cdk-examples/issues/110#issuecomment-550506116 without luck.

What am I missing?

badfun
  • 145
  • 1
  • 10
  • What is your directory structure in this project? I have deployed a few apps having lambda within CDK and using cdk-pipelines successfully. Also, what is your CDK code for deploying the lambda, this might help in getting to the actual problem – user3789185 Sep 18 '20 at 12:32
  • Did you have dependencies with your lambdas? That is the issue I was having. – badfun Sep 19 '20 at 17:39

1 Answers1

1

Looks like the issue has to do with bundling. I abandoned the 'all-in on CDK approach' and went back to using a SAM/CDK hybrid, but this new blog post suggests bundling is the answer.

https://aws.amazon.com/blogs/devops/building-apps-with-aws-cdk/

Specifically, it references this construct, which likely would have helped in my situation: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.html

Something to try in future.

badfun
  • 145
  • 1
  • 10