Skip to content

Commit 4e9ff07

Browse files
authored
feat(ci): Add advanced automation (#3438)
1 parent 95762ad commit 4e9ff07

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

Diff for: .github/workflows/bootstrap_region.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# bootstraps new regions
2+
#
3+
# PURPOSE
4+
# Ensures new regions are deployable in future releases
5+
#
6+
# JOB 1 PROCESS
7+
#
8+
# 1. Installs CDK
9+
# 2. Bootstraps region
10+
#
11+
# JOB 2 PROCESS
12+
# 1. Sets up Go
13+
# 2. Installs the balance script
14+
# 3. Runs balance script to copy layers between aws regions
15+
16+
on:
17+
workflow_dispatch:
18+
inputs:
19+
environment:
20+
type: choice
21+
options:
22+
- beta
23+
- prod
24+
description: Deployment environment
25+
region:
26+
type: string
27+
required: true
28+
description: AWS region to bootstrap (i.e. eu-west-1)
29+
30+
name: Region Bootstrap
31+
run-name: Region Bootstrap ${{ inputs.region }}
32+
33+
permissions:
34+
contents: read
35+
36+
jobs:
37+
cdk:
38+
name: Install CDK
39+
runs-on: ubuntu-latest
40+
permissions:
41+
contents: write
42+
id-token: write
43+
environment: layer-${{ inputs.environment }}
44+
steps:
45+
- id: credentials
46+
name: AWS Credentials
47+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
48+
with:
49+
aws-region: ${{ inputs.region }}
50+
role-to-assume: ${{ secrets.REGION_IAM_ROLE }}
51+
mask-aws-account-id: true
52+
- id: workdir
53+
name: Create Workdir
54+
run: |
55+
mkdir -p build/project
56+
- id: cdk-install
57+
name: Install CDK
58+
working-directory: build
59+
run: |
60+
61+
- id: cdk-project
62+
name: CDK Project
63+
working-directory: build/project
64+
run: |
65+
npx cdk init app --language=typescript
66+
AWS_REGION="${{ inputs.region }}" npx cdk bootstrap
67+
68+
copy_layers:
69+
name: Copy Layers
70+
runs-on: ubuntu-latest
71+
permissions:
72+
contents: write
73+
id-token: write
74+
environment: layer-${{ inputs.environment }}
75+
steps:
76+
- id: credentials
77+
name: AWS Credentials
78+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
79+
with:
80+
aws-region: us-east-1
81+
role-to-assume: ${{ secrets.REGION_IAM_ROLE }}
82+
mask-aws-account-id: true
83+
- id: go-setup
84+
name: Setup Go
85+
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
86+
with:
87+
go-version: '>=1.23.0'
88+
- id: go-env
89+
name: Go Env
90+
run: go env
91+
- id: go-install-pkg
92+
name: Install
93+
run: go install github.com/aws-powertools/actions/layer-balancer/cmd/balance@latest
94+
- id: run-balance
95+
name: Run Balance
96+
run: balance -read-region us-east-1 -write-region ${{ inputs.region }} -write-role ${{ secrets.BALANCE_ROLE_ARN }} -layer-name AWSLambdaPowertoolsTypeScriptV2 -dry-run=false

Diff for: .github/workflows/update_ssm.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# SSM Parameters update
2+
#
3+
# PROCESS
4+
# Creates parameters in regional AWS accounts for each layer we create, using the inputs to target specific releases
5+
# * environment: will prefix /beta/ into the parameter
6+
# * write_latest: will create a latest alias instead of a version number in the parameter
7+
# * package_version: semantic version number of the released layer (3.x.y)
8+
# * layer_version: this is sequential layer version from the ARN
9+
#
10+
# A successful parameter would look similar to:
11+
# /aws/service/powertools/python/arm64/python3.8/3.1.0
12+
# And will have a value of:
13+
# arn:aws:lambda:eu-west-1:094274105915:layer:AWSLambdaPowertoolsPythonV3-python38-arm64:4
14+
15+
on:
16+
workflow_dispatch:
17+
inputs:
18+
environment:
19+
description: Environment to deploy to
20+
type: choice
21+
options:
22+
- Beta
23+
- Prod
24+
required: true
25+
26+
write_latest:
27+
description: Write to the latest path
28+
type: boolean
29+
required: false
30+
31+
package_version:
32+
description: Semantic Version of published layer
33+
type: string
34+
required: true
35+
36+
layer_version:
37+
description: Layer version
38+
type: string
39+
required: true
40+
41+
name: SSM Parameters
42+
run-name: SSM Parameters - TypeScript
43+
44+
permissions:
45+
contents: read
46+
47+
jobs:
48+
typescript:
49+
runs-on: ubuntu-latest
50+
environment: SSM
51+
strategy:
52+
matrix:
53+
region: ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3",
54+
"ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3",
55+
"ap-southeast-4", "ca-central-1", "ca-west-1", "eu-central-1", "eu-central-2",
56+
"eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3",
57+
"il-central-1", "me-central-1", "me-south-1", "sa-east-1", "us-east-1",
58+
"us-east-2", "us-west-1", "us-west-2", "ap-southeast-5"
59+
]
60+
61+
permissions:
62+
contents: write
63+
id-token: write
64+
steps:
65+
- id: transform
66+
run: |
67+
echo 'CONVERTED_REGION=${{ matrix.region }}' | tr 'a-z\-' 'A-Z_' >> "$GITHUB_OUTPUT"
68+
- id: creds
69+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
70+
with:
71+
aws-region: ${{ matrix.region }}
72+
role-to-assume: ${{ secrets[format('{0}', steps.transform.outputs.CONVERTED_REGION)] }}
73+
mask-aws-account-id: true
74+
- id: write-version
75+
env:
76+
prefix: ${{ inputs.environment == 'beta' && '/aws/service/powertools/beta' || '/aws/service/powertools' }}
77+
run: |
78+
aws ssm put-parameter --name ${{ env.prefix }}/typescript/generic/all/${{ inputs.package_version }} --value "arn:aws:lambda:${{ matrix.region }}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:${{ inputs.layer_version }}" --type String --overwrite
79+
80+
- id: write-latest
81+
if: inputs.write_latest == true
82+
env:
83+
prefix: ${{ inputs.environment == 'beta' && '/aws/service/powertools/beta' || '/aws/service/powertools' }}
84+
run: |
85+
aws ssm put-parameter --name ${{ env.prefix }}/generic/all/latest --value "arn:aws:lambda:${{ matrix.region }}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:${{ inputs.layer_version }}" --type String --overwrite

0 commit comments

Comments
 (0)