skip to Main Content

I recently started developing a serverless application using the AWS CDK with TypeScript, and I find it much more efficient than managing everything through the console. I can host my code in a repository, and the organization and maintenance benefits significantly from this approach. However, one advantage of using the AWS Console was the ability to quickly test code. You could write a Lambda function and test it instantly without any issues. In contrast, with the CDK, you first need to deploy, push updates to the cloud, and only then test them. Is there a way to test CDK applications locally? Not just Lambda functions, but something that simulates AWS services as a whole?

2

Answers


  1. It sounds like what you’re after is LocalStack ( see https://github.com/localstack/localstack ). There is a free and paid version of this product, where the latter is far more advanced and feature-rich.
    Here’s a link showing a run down of the supported APIs and emulated services:
    https://docs.localstack.cloud/user-guide/aws/feature-coverage/

    Login or Signup to reply.
  2. I have dealt with CDK testing in the past extensively let me break this for you.

    • There are 2 separations of the overall testing process when dealing with CDK tests.
      • Application layer like creating Lambda function by CDK
      • AWS service or infrastructure resource created by CDK
    1. Testing Application layer like creating Lambda function by CDK

    2. Testing AWS service or infrastructure resource created by CDK

    • There are 2 kinds of tests:
      • Fine-grained assertions ( most common form of CDK test) : This tests "this resource has this property with this value."
      • Snapshot tests: test the synthesized AWS CloudFormation template against a previously stored baseline template. I will think more of this as integration test for CDK infra resources.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search