This project was used as a learning tool to figure out how to develop a production-grade CI / CD workflow that would minimize the risk of publishing bad code into production AWS environments.
Access application frontend: https://riskyfrisky.github.io/DevTestProdAWS
Pre-requisites
- Bun: https://bun.sh/docs/installation
- Tools for deploying on LocalStack
- Tools for deploying on AWS
Setup
bun i
cd $(git rev-parse --show-toplevel)/Lambda/Layer/nodejs
bun iUnit Test
cd $(git rev-parse --show-toplevel)/Lambda/__test__/unit
bun testBuild
cd $(git rev-parse --show-toplevel)/Lambda/Layer/nodejs
bun run compile
cd $(git rev-parse --show-toplevel)/Cloudformation
samlocal build --template-file template.yaml
or
sam build --template-file template.yamlDeploy on LocalStack (Requires PRO account for LambdaLayer use)
- Get auth token from https://app.localstack.cloud/workspace/auth-token & set in
.envfile
cd $(git rev-parse --show-toplevel)/Lambda/__test__/integration/localstack
docker compose --env-file $(git rev-parse --show-toplevel)/.env up
awslocal s3 mb s3://devtestprodaws
cd $(git rev-parse --show-toplevel)/Cloudformation
samlocal deploy --config-file samconfig.toml --capabilities CAPABILITY_NAMED_IAM --no-confirm-changeset-
Integration test
export FUNCTION_URL=$(awslocal lambda list-function-url-configs --function-name devtestprodaws-main | grep -o '"FunctionUrl": "[^"]*' | awk -F'"' '{print $4}') cd $(git rev-parse --show-toplevel)/Lambda/__test__/integration bun test
Deploy on AWS
- Create a unique bucket name in AWS cloud first (e.g. devtestprodaws-2) & update samconfig.toml
s3_bucketvalue
cd $(git rev-parse --show-toplevel)/Cloudformation
sam deploy --config-file samconfig.toml --capabilities CAPABILITY_NAMED_IAM --no-confirm-changesetTest action locally with act
gh act --secret-file .env --job unit-test-job
gh act --secret-file .env --job integration-test-job
gh act --job deploy-job