This is a simple exercise to get to know CDK better.
At the end of this exercise, you should be able to deploy AWS resources shown in the architecture diagram below. We are going to setup a Lambda backed Rest API Gateway, that performs CRUD operations on DynamoDB table. On top of that, we are going to stream the changes to each table onto another Lambda.
- Install Node
https://github.com/coreybutler/nvm-windows
- Install and configure AWS CLI
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
- Install CDK
Since this exercise is using typescript, use the following:
npm i -g aws-cdk
- Install typescript
npm i -g typescript
- From the root folder (where the README.md file is) creates
deploy
folder. - Navigate to
deploy
folder. - If this is the first time you use CDK. You might need to run
cdk bootstrap
. Otherwise runcdk init app --language typescript
to initialise CDK project. - Run
npm run build
to build the project. - Run
cdk synth
to emit CloudFormation template.
- Open
lab-cdk
folder on your favorite IDE. - Open
lib/deploy-stack.cs
file. - Using CDK construct, create
DynamoDbProxyLambda
lambda. The source code is available onsrc/dynamodb-proxy-lambda/index.js
. - Using CDK construct, create
DynamoDbApiGateway
Rest API Gateway for that Lambda. - Using CDK construct, create DynamoDb table
table1
. - Grant
DynamoDbProxyLambda
lambda, read and write access to DynamoDb tabletable1
. - Run
npm run build
to build the project. - Run
cdk synth
to emit CloudFormation template.
- Open
lib/deploy-stack.cs
file. - Using CDK construct, create
StreamLogger
lambda. The source code is available onsrc/stream-logger-lambda/index.js
. - Update DynamoDb table
table1
to stream record changes - Make
StreamLogger
lambda to handletable1
stream - Run
npm run build
to build the project. - Run
cdk synth
to emit CloudFormation template.
- Open
lib/deploy-stack.cs
file. - Create custom CDK construct for resources created in Exercise 3
- Bonus exercise: Create another DynamoDb
table2
, and stream its record changes to the sameStreamLogger
lambda by using the same custom CDK construct.
- Edwin Sukirno