This GitHub Actions workflow automates the deployment of an AWS CDK stack to a development and production environment. It is triggered when changes are pushed to the develop
or main
branch. The workflow sets up AWS credentials, installs dependencies, and deploys the CDK stack.
- Run Name: Running ${{github.workflow}} off of ${{ github.ref_name }}
This workflow is triggered on pushes to the develop
branch.
on:
push:
branches:
- develop
This workflow requires specific permissions:
id-token: write
: This is required for requesting the JWT.contents: read
: This is required for actions/checkout.
- Name: Deploy Development
- Uses:
./.github/workflows/deploy.yaml
- Environment: development
- Run Name: Running ${{github.workflow}} off of ${{ github.ref_name }}
This workflow is triggered on pushes to the main
branch.
on:
push:
branches:
- main
This workflow requires specific permissions:
id-token: write
: This is required for requesting the JWT.contents: read
: This is required for actions/checkout.
- Name: Deploy Production
- Uses:
./.github/workflows/deploy.yaml
- Environment: production
This workflow is designed to be called by other workflows and is used for deploying to different environments. It sets up AWS credentials, installs dependencies, and deploys the CDK stack based on the specified environment.
This workflow is meant to be called by other workflows using the workflow_call
event. It takes an environment
input parameter.
on:
workflow_call:
inputs:
environment:
required: true
type: string
description: "The GitHub environment to deploy against."
This workflow also requires specific permissions:
id-token: write
: Required for requesting the JWT.contents: read
: Required for actions/checkout.
- Name: Deploy to ${{ inputs.environment }}
- Environment: ${{ inputs.environment }}
-
Environment Variables:
-
ENVIRONMENT
: ${{ vars.ENVIRONMENT }} -
CDK_DEPLOY_ACCOUNT
: ${{ vars.ACCOUNT_ID }} -
CDK_DEPLOY_REGION
: ${{ vars.REGION }}
-
- Runs On: ubuntu-latest
-
Defaults:
- Working Directory:
src
- Working Directory:
-
Checkout Repository: This step checks out the repository to the GitHub Actions runner.
- name: Checkout uses: actions/checkout@v3
-
Configure AWS Credentials: This step configures AWS credentials for the specified environment.
- name: Configure AWS Credentials ${{ inputs.environment }} uses: aws-actions/configure-aws-credentials@v2 with: role-to-assume: arn:aws:iam::${{ vars.ACCOUNT_ID }}:role/${{ vars.DEPLOYMENT_ROLE}} role-session-name: cdk-deployment-${{ vars.REGION }}-${{ vars.ACCOUNT_ID }} aws-region: ${{ vars.REGION }}
-
Install Dependencies: This step installs necessary dependencies, including AWS CDK and Python requirements.
- name: Install Dependencies run: | npm install -g aws-cdk pip install -r requirements.txt
-
CDK Synth: This step runs
cdk synth
to generate CloudFormation templates.- name: CDK Synth run: | cdk synth
-
Deploy CDK Stack: This step deploys the CDK stack using
cdk deploy
with no approval required.- name: Deploy NumberGuessingGame run: | cdk deploy --app 'cdk.out/' --all --require-approval never