This is the public infrastructure code of my blog (https://www.playingaws.com). This project is an example of a CDK project with 2 stacks: the infrastructure (backend) and the CICD to automate the infrastructure deployment.
CDK project using TypeScript. It contains 2 stacks:
Backend: This stack contains the infrastructure to be deployedAPI Gatewayusing a custom domain (api.playingaws.com)Lambda: subscription and contactDynamoDBCloudWatch: lambda alarm and dashboard of lambdas
CICD: This stack contains the automation of the backend infrastructureCodePipelinewith 2 stages- source:
CodeCommitwith GitHub - build:
CodeBuild(executes terraform apply)
- source:
S3(as artifactory in CodePipeline)
Architecture diagram - autogenerated with cdk-dia
Public code
npm run lint && npm run test-
Download and run docker image of dynamodb-local
docker pull amazon/dynamodb-local docker run -p 8000:8000 amazon/dynamodb-local
-
Create dynamodb-local tables - review the template.yaml because the ID is going to change
aws dynamodb create-table --table-name bloginfrastructuresubscriptiondbF44CF6DE --attribute-definitions AttributeName=email,AttributeType=S --key-schema AttributeName=email,KeyType=HASH --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 --endpoint-url http://localhost:8000 aws dynamodb create-table --table-name bloginfrastructurecontactdbA1E13C61 --attribute-definitions AttributeName=name,AttributeType=S --key-schema AttributeName=name,KeyType=HASH --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 --endpoint-url http://localhost:8000
-
Update lambda code to change the endpoint:
const dbClient = process.env.AWS_SAM_LOCAL ? new DynamoDBClient({ endpoint: 'http://docker.for.mac.localhost:8000/', }) : new DynamoDBClient();
-
Generate the YAML file that SAM needs
cdk synth blog-backend-infrastructure --no-staging > template.yml -
Run SAM tests
sam local invoke blog-backend-infrastructure-contact-lbd -e tests/events/contact.json sam local invoke blog-backend-infrastructure-subscription-lbd -e tests/events/subscription.json
-
Review database records
aws dynamodb scan --table-name bloginfrastructuresubscriptiondbF44CF6DE --endpoint-url http://localhost:8000 aws dynamodb scan --table-name bloginfrastructurecontactdbA1E13C61 --endpoint-url http://localhost:8000
