This is a repo with minimal code to demo a way to do CI/CD with the AWS CDK for TypeScript and Github Actions. As demoed on The Zacks' Show Talking AWS.
- Install Node.js
- Ensure you have at least one AWS account, install the AWS CLI, and configure your credentials
- Install Docker - I personally like to use Docker Desktop
- Needed for CI/CD: configure the AWS accounts you would like Github actions to deploy into - I personally forked this repo, did some light edits, and ran
cdk deployto provision the OIDC identity provider + role for Github actions to assume into my development, staging, and production AWS accounts. - Needed for CI/CD slack notifications: setup a Slack bot with
chat:writepermissions. Add repo level secrets forDEVOPS_NOTIFICATIONS_SLACK_CHANNEL_IDandSLACK_DEPLOY_BOT_TOKENinto Github. - Needed for CI/CD: set up Github Environments for
ci,development,staging, andproduction. Add in a secret in each env forAWS_ROLE_TO_ASSUME. Add in and env var in each env forSTAGE.
- Clone the repo
- Run
npm install - Run
export AWS_PROFILE=<your_aws_profile>- Optional if you have a default profile or use
--profileinstead - There's also other ways to do this too if preferred
- Optional if you have a default profile or use
- Run
export STAGE=<your_stage_name> - Run
npm run deploy
This is a minimal API Gateway with API Key auth > Lambda > DynamoDB setup
- Get the API Key id and URL from the stack output of the
cdk deploy - Run ``aws apigateway get-api-key --api-key your-api-id --include-value` > copy the value
- add
/my-apito the end of the url - Run a curl command or use something like Postman to make API calls something like
curl --location 'https://api-id.execute-api.aws-region.amazonaws.com/v1/my-api' \
--header 'x-api-key: your-api-key'- There's also a POST endpoint where you can input anything in the body (not best practice but this is minimal demo of CI/CD not code)
curl --location 'https://api-id.execute-api.aws-region.amazonaws.com/v1/my-api' \
--header 'x-api-key: your-api-key' \
--header 'Content-Type: application/json' \
--data '{
"name": "Danielle Heberling",
"species": "Human"
}'- If you open a PR against the
mainbranch it will run the.github/workflows/ci.ymlworkflow to run some CI checks. - Merging into
mainwill trigger the.github/workflows/dev-deploy.ymlworkflow to deploy to dev. - Creating a Github release (or git tag) that starts with
release-*triggers a deploy to staging via.github/workflows/stg-prod-deploy.yml. In that same workflow if a deploy to stg succeeds, it will deploy it to prod. - If any of the deployments fail, a message will be sent to the designated slack channel.
npm run buildruns all of the commands that would be run in CI locally on your machinenpm run deploydeploys to the AWS account your AWS CLI is logged into (ideally this is a developer's own AWS account)npm run diffrunscdk diffagainst the AWS account your CLI is logged into to see what changes would happen if you deploy