Learn how to prepare your application to take it from your development environment into a deployment ready to receive users.
Stash secrets in AWS Systems Manager Parameter Store. The actual secrets to store are defined in ecs-task-definition.json
staging
- deploys to stagingmaster
or release
- deploys to productionWire the deploy GitHub Action to be invoked on push to the designated branch names
Create DNS entries on Cloudflare that point the root domain and www subdomain to the load balancer
The GitHub Actions CI workflow (ci.yml
) uses GitHub OIDC to authenticate with AWS.
This has several benefits over using AWS access keys:
Read more on OIDC here.
The simplest way to set this up is using CloudFormation. In the root AWS account, create a CloudFormation stack:
Parameters:
GitHubOrg:
Type: String
RepositoryName:
Type: String
OIDCProviderArn:
Description: Arn for the GitHub OIDC Provider.
Default: ""
Type: String
Conditions:
CreateOIDCProvider: !Equals
- !Ref OIDCProviderArn
- ""
Resources:
Role:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRoleWithWebIdentity
Principal:
Federated: !If
- CreateOIDCProvider
- !Ref GithubOidc
- !Ref OIDCProviderArn
Condition:
StringLike:
token.actions.githubusercontent.com:aud: sts.amazonaws.com
token.actions.githubusercontent.com:sub: !Sub repo:${GitHubOrg}/${RepositoryName}:*
Policies: # TODO - Attach any other policies you need to deploy your app (ECR, EB)
- PolicyName: DeployToSomeS3Bucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:DeleteObject
- s3:GetBucketLocation
- s3:GetObject
- s3:ListBucket
- s3:PutObject
- s3:ListObjectsV2
Resource: arn:aws:s3:::<s3-bucket-name>/*
GithubOidc:
Type: AWS::IAM::OIDCProvider
Condition: CreateOIDCProvider
Properties:
Url: https://token.actions.githubusercontent.com
ClientIdList:
- sts.amazonaws.com
ThumbprintList:
- 6938fd4d98bab03faadb97b34396831e3780aea1
- 1c58a3a8518e8759bf075b76b750d4f2df264fcd
Outputs:
Role:
Value: !GetAtt Role.Arn
The stack creates a role that is assumed by the GitHub Action. The stack provided allows the role to sync with an S3 bucket. You must add any policies required to deploy your application to that role.
The stack will prompt for a few inputs:
GitHubOrg
: This should be either datagovsg
or opengovsg
RepositoryName
: The repository the GitHub Action will run onOIDCProviderARN
:
After creating the resources, navigate to the GitHub OIDC Provider created, and copy the ARN.
In the GitHub Action’s env vars, set:
AWS_ROLE_ARN
: the copied ARNAWS_REGION
: the region of the AWS accountThat’s it!
Terraform version coming soon…