最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - Testing AWS CDK Applications Locally - Stack Overflow

programmeradmin2浏览0评论

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 anization 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?

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 anization 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?

Share Improve this question edited Jan 19 at 16:32 Jatin Mehrotra 11.6k4 gold badges49 silver badges113 bronze badges asked Jan 18 at 5:24 OrlindoOrlindo 157 bronze badges 1
  • posted an answer which explains about CDK stack testing process. – Jatin Mehrotra Commented Jan 19 at 3:43
Add a comment  | 

2 Answers 2

Reset to default 2

It sounds like what you're after is LocalStack ( see https://github/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/

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

    • Treat this as your everyday piece of application code
    • For this you should do the same set of application testing you do like unit testing and integration testing using frameworks like Jest or pytest.
    • Even CDK docs also says the same on testing your lambda function and they provided commands as well.
  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.
发布评论

评论列表(0)

  1. 暂无评论