In this assignment we will focus on:
- AWS Services (without requiring an AWS Account)
- CDK for Terraform (Python)
- GitHub Workflow Integration test
Implement Localstack: Quickstart in CDKTF.
Please make sure that you have the following working on your machine:
- NodeJS installation
- Python3 / pipenv
- Docker environment
- Terraform (i.e. managed through tfenv)
- AWS cli only (we will use localstack so no aws credentials required)
- utilities
jq
,zip
&curl
See also this CDKTF and Localstack getting started guides:
MacOS tips
which python3
which docker
pip3 install --user pipenv
# Ensure pipenv is on path, or else.. add
export PATH=/Users/${USER}/Library/Python/3.11/bin:$PATH
Ensure CDKTF CLI is set up
npm i -g [email protected]
pipenv shell
DEBUG=1 EXTRA_CORS_ALLOWED_ORIGINS=* localstack start -d
# check status
localstack status
Note: To see SNS Emails, should be able to use DATA_DIR see: issue comment.
This repo has been modified to be deployed using IaC with CDKTF. 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.
images
andresized
S3 bucketslist
,presign
andresize
Lambda Functions- S3 bucket event trigger for
resize
Lambda Function
- 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
Run in
pipenv shell
cdktf synth
TERRAFORM_BINARY_NAME=tflocal cdktf apply iac-assignment-backend
You may use
--skip-synth
to speed up apply.
webapp
S3 bucket.env.local
file with Env config
- Create S3 bucket for webapp
- Create webapp S3 Bucket website configuration and s3 policy
Run in
pipenv shell
TERRAFORM_BINARY_NAME=tflocal cdktf apply iac-assignment-frontend
Copy website
to webapp
S3 Bucket (uses website/.env.local
config from cdktf apply
):
npm --prefix website install
npm --prefix website run deploy
Run in
pipenv shell
pytest tests/
Make the GitHub Workflow pass
- Set up CDKTF cli in GitHub Runner
- Deploy Backend with CDKTF
- Deploy Frontend with CDKTF
- Refactor IaC to split backend and frontend stacks in separate code files
- Implement CDKTF Unit tests in main-test.py
- Implement Unit tests for
list
,presign
andresize
functions - Run Unit tests in pre-commit
LocalStack debug logs show lambda invocations and logs:
localstack logs -f
To check resize dead letter notifications:
curl -s http://localhost:4566/_aws/ses | jq -r '.messages[0] | {Destination, "Message": (.Body.text_part | fromjson)}'