Menu

Test CDK stacks: template assertions with Vitest
📰

Test CDK stacks: template assertions with Vitest

DEV Community: typescript·Sascha Mirow-Stanitzok·4 days ago
#kSKgLSBY
#devtotypescript#devto#dev#test#stack
Reading 0:00
15s threshold

Many teams only start to test CDK stacks after a deployment has gone wrong: the table suddenly disappeared because someone changed the removalPolicy , or the Lambda function was allowed to do anything in DynamoDB. A test would have caught both in a few milliseconds. What I like about the AWS CDK is that infrastructure is plain TypeScript code. Taken to its logical end, that also means this code deserves tests like any other code.

In this article, we build a small stack for a fictional city library together: reservations land in an SQS queue, a Lambda function writes them to DynamoDB, and broken messages move to a dead-letter queue. We test this stack with the aws-cdk-lib/assertions module and Vitest , entirely without an AWS account.

In short

The CDK turns your code into a CloudFormation template, and you check exactly that template with Template.fromStack and targeted assertions, locally and within seconds.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.