Important
This quickstart has been tested on Darwin/Linux only - recommended to use WSL if on Windows.
In this assignment we will focus on:
- AWS Services (without requiring an AWS Account)
- CDK for Terraform (Typescript) (in future: CDK Terrain)
- GitHub Workflow Integration test
The task is to implement this Localstack: Quickstart in CDKTF!
Note
Handshakes is adopting CDK Terrain for longterm support since Hashicorp has sunset CDKTF.
Please make sure that you have the following working on your machine:
-
AWS cli only (we will use localstack so no aws credentials required)
-
NodeJS installation - we use mise
mise trust . # installs node, terraform, localstack, terraform-local, awscli-local, ... mise install # NodeJS shims for pnpm/yarn using corepack corepack enable pnpm install
-
Docker environment - we use colima on MacOS - not in repo dependencies, may use global install:
mise use -g colima@latest
-
Terraform (i.e. managed through mise)
# should show terraform version installed by mise from step above mise ls -
standard utilities
jq,zip&curl
See also this CDKTF getting started guides:
Pre-Req (automated with mise install above)
node --version # 20.x pinned
terraform --version # 1.7.5 pinned
localstack --version # 4.12.0 pinned
tflocal --version # localstack wrapper for terraform
awslocal --version # localstack wrapper for aws cli
docker version # colima glabal installEnsure all required dependencies are installed
pnpm ipnpm localstack:startNote: To see SNS Emails, should be able to use DATA_DIR see: issue comment.
This repo has been modified to be deployed using CDKTF IaC. The ultimate goal is to make the GH Workflow pass.
The exact shell commands to achieve a working configuration are in deploy.sh
However, you may only run cdktf commands in GH Runner to achieve the working configuration.
Important
Fix the ./main.ts file to implement the following TODOs across both stacks.
imagesandresizedS3 bucketslist,presignandresizeLambda Functions- S3 bucket event trigger for
resizeLambda Function
Note
Ask the AI Agent to write Unit Tests first before implementing as fast feedback loop (TDD).
- Create S3 buckets
- Create SSM Paramaters for Lambda handlers to work
- Create SNS Topic to receive dead letter notifications when resize lambda fails
- Create resize lambda
- Create images bucket event trigger for resize lambda
pnpm synth
TERRAFORM_BINARY_NAME=tflocal pnpm exec cdktf apply iac-assignment-backendYou may use
--skip-synthto speed up apply.
webappS3 bucket.env.localfile with Env config
- Create S3 bucket for webapp
- Create webapp S3 Bucket website configuration and s3 policy
TERRAFORM_BINARY_NAME=tflocal pnpx cdktf apply iac-assignment-frontendCopy website to webapp S3 Bucket (uses website/.env.local config from cdktf apply):
pnpm --prefix website install
pnpm --prefix website run deploy-
Run integration tests:
pnpm test:integ
-
Verify both tests pass:
- Image resize test uploads and verifies smaller resized image
- Failure test triggers error email via SNS/SES
Note: The GitHub Actions workflow won't run tests successfully until the CDKTF deployment TODOs are implemented.
Make the GitHub Workflow pass
- Set up CDKTF cli in GitHub Runner
- Deploy Backend with CDKTF
- Deploy Frontend with CDKTF
- Implement CDKTF Unit tests in main.test.ts
- Implement Unit tests for
list,presignandresizefunctions - Refactor IaC to split backend and frontend stacks in separate code files
- Run Unit tests in pre-commit
LocalStack debug logs show lambda invocations and logs:
localstack logs -fTo check resize dead letter notifications:
curl -s http://localhost:4566/_aws/ses | jq -r '.messages[0] | {Destination, "Message": (.Body.text_part | fromjson)}' 
