0
votes

Using aws-cdk (Typescript) to deploy an environment containing Lambdas, basics are working well but now I want to move onto developing the Lambdas and I'm confused about unit testing in the context of the CDK.

The CDK is using Jest for unit testing, am I able to use Mocha and Chai for my Lambda's or do I need to use Jest?

I think Jest makes sense for the CDK but I like Mocha\Chai for testing my business logic within the Lambdas.

1

1 Answers

1
votes

The CDK is a development toolkit to mainly transcompile code written in the language that you choose to CloudFormation templates. If you want to test a lambda code using Mocha or Chai, you can test it locally and pack code and dependencies into a zip file as you do when using Lambda itself.

I usually use a deploy pipeline containing two build stages: one is to compile and pack a lambda function and upload to S3, the other one is to transcompile CDK stacks to a CloudFormation template that refers and uses the zipped lambda function.