Infrastructure as Code with AWS CDK
Building the stack for a simple serverless app using TypeScript
If you’re working with AWS CloudFormation, you may find your stacks cumbersome to define. Fancy moving away from JSON or YAML and instead implementing your infrastructure with an imperative programming language?
Released for developer preview since July 2018, the AWS Cloud Development Kit (CDK) is an open-source project that aims to address these concerns. Supporting Java, JavaScript, Python, TypeScript, and .NET, the CDK makes it easier than ever before to define your AWS stacks.
With a simple, serverless application in mind to save requests to a NoSQL table, let’s build the stack for this app using the General Availability release of the CDK (version 1.0.0) for TypeScript.
Design
We require three AWS services for this app: API Gateway to send requests, DynamoDB to store these requests in a NoSQL table, and Lambda to execute the code that validates and saves these requests to DynamoDB.
API Gateway will consist of a single endpoint, /send
. This endpoint will support POST requests. Every time a POST request is made to this endpoint, we will trigger the Lambda function.