1
+ # GovCloud Layer Publish
2
+ # ---
3
+ # This workflow publishes a specific layer version in an AWS account based on the environment input.
4
+ #
5
+ # Using a matrix, we pull each architecture and python version of the layer and store them as artifacts
6
+ # we upload them to each of the GovCloud AWS accounts.
7
+ #
8
+ # A number of safety checks are performed to ensure safety.
9
+
10
+ on :
11
+ workflow_dispatch :
12
+ inputs :
13
+ environment :
14
+ description : Deployment environment
15
+ type : choice
16
+ options :
17
+ - Gamma
18
+ - Prod
19
+ required : true
20
+ version :
21
+ description : Layer version to duplicate
22
+ type : string
23
+ required : true
24
+ workflow_call :
25
+ inputs :
26
+ environment :
27
+ description : Deployment environment
28
+ type : string
29
+ required : true
30
+ version :
31
+ description : Layer version to duplicate
32
+ type : string
33
+ required : true
34
+
35
+ name : Layer Deployment (GovCloud)
36
+ run-name : Layer Deployment (GovCloud) - ${{ inputs.environment }}
37
+
38
+ jobs :
39
+ download :
40
+ runs-on : ubuntu-latest
41
+ permissions :
42
+ id-token : write
43
+ contents : read
44
+ strategy :
45
+ matrix :
46
+ layer :
47
+ - AWSLambdaPowertoolsPythonV3-python38
48
+ - AWSLambdaPowertoolsPythonV3-python39
49
+ - AWSLambdaPowertoolsPythonV3-python310
50
+ - AWSLambdaPowertoolsPythonV3-python311
51
+ - AWSLambdaPowertoolsPythonV3-python312
52
+ arch :
53
+ - arm64
54
+ - x86_64
55
+ environment : Prod (Readonly)
56
+ steps :
57
+ - name : Configure AWS Credentials
58
+ uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
59
+ with :
60
+ role-to-assume : ${{ secrets.AWS_IAM_ROLE }}
61
+ aws-region : us-east-1
62
+ mask-aws-account-id : true
63
+ - name : Grab Zip
64
+ run : |
65
+ aws --region us-east-1 lambda get-layer-version-by-arn --arn arn:aws:lambda:us-east-1:017000801446:layer:${{ matrix.layer }}-${{ matrix.arch }}:${{ inputs.version }} --query 'Content.Location' | xargs curl -L -o ${{ matrix.layer }}_${{ matrix.arch }}.zip
66
+ aws --region us-east-1 lambda get-layer-version-by-arn --arn arn:aws:lambda:us-east-1:017000801446:layer:${{ matrix.layer }}-${{ matrix.arch }}:${{ inputs.version }} > ${{ matrix.layer }}_${{ matrix.arch }}.json
67
+ - name : Store Zip
68
+ uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
69
+ with :
70
+ name : ${{ matrix.layer }}_${{ matrix.arch }}.zip
71
+ path : ${{ matrix.layer }}_${{ matrix.arch }}.zip
72
+ retention-days : 1
73
+ if-no-files-found : error
74
+ - name : Store Metadata
75
+ uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
76
+ with :
77
+ name : ${{ matrix.layer }}_${{ matrix.arch }}.json
78
+ path : ${{ matrix.layer }}_${{ matrix.arch }}.json
79
+ retention-days : 1
80
+ if-no-files-found : error
81
+
82
+ copy_east :
83
+ name : Copy (East)
84
+ needs : download
85
+ runs-on : ubuntu-latest
86
+ permissions :
87
+ id-token : write
88
+ contents : read
89
+ strategy :
90
+ matrix :
91
+ layer :
92
+ - AWSLambdaPowertoolsPythonV3-python38
93
+ - AWSLambdaPowertoolsPythonV3-python39
94
+ - AWSLambdaPowertoolsPythonV3-python310
95
+ - AWSLambdaPowertoolsPythonV3-python311
96
+ - AWSLambdaPowertoolsPythonV3-python312
97
+ arch :
98
+ - arm64
99
+ - x86_64
100
+ environment : GovCloud ${{ inputs.environment }} (East)
101
+ steps :
102
+ - name : Download Zip
103
+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
104
+ with :
105
+ name : ${{ matrix.layer }}_${{ matrix.arch }}.zip
106
+ - name : Download Metadata
107
+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
108
+ with :
109
+ name : ${{ matrix.layer }}_${{ matrix.arch }}.json
110
+ - name : Verify Layer Signature
111
+ run : |
112
+ SHA=$(jq -r '.Content.CodeSha256' '${{ matrix.layer }}_${{ matrix.arch }}.json')
113
+ test "$(openssl dgst -sha256 -binary ${{ matrix.layer }}_${{ matrix.arch }}.zip | openssl enc -base64)" == "$SHA" && echo "SHA OK: ${SHA}" || exit 1
114
+ - name : Configure AWS Credentials
115
+ uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
116
+ with :
117
+ role-to-assume : ${{ secrets.AWS_IAM_ROLE }}
118
+ aws-region : us-gov-east-1
119
+ mask-aws-account-id : true
120
+ - name : Create Layer
121
+ id : create-layer
122
+ run : |
123
+ LAYER_VERSION=$(aws --region us-gov-east-1 lambda publish-layer-version \
124
+ --layer-name ${{ matrix.layer }}-${{ matrix.arch }} \
125
+ --zip-file fileb://./${{ matrix.layer }}_${{ matrix.arch }}.zip \
126
+ --compatible-runtimes "$(jq -r '.CompatibleRuntimes[0]' '${{ matrix.layer }}_${{ matrix.arch }}.json')" \
127
+ --compatible-architectures "$(jq -r '.CompatibleArchitectures[0]' '${{ matrix.layer }}_${{ matrix.arch }}.json')" \
128
+ --license-info "MIT-0" \
129
+ --description "$(jq -r '.Description' '${{ matrix.layer }}_${{ matrix.arch }}.json')" \
130
+ --query 'Version' \
131
+ --output text)
132
+
133
+ echo "LAYER_VERSION=$LAYER_VERSION" >> "$GITHUB_OUTPUT"
134
+
135
+ aws --region us-gov-east-1 lambda add-layer-version-permission \
136
+ --layer-name '${{ matrix.layer }}-${{ matrix.arch }}' \
137
+ --statement-id 'PublicLayer' \
138
+ --action lambda:GetLayerVersion \
139
+ --principal '*' \
140
+ --version-number "$LAYER_VERSION"
141
+ - name : Verify Layer
142
+ env :
143
+ LAYER_VERSION : ${{ steps.create-layer.outputs.LAYER_VERSION }}
144
+ run : |
145
+ REMOTE_SHA=$(aws --region us-gov-east-1 lambda get-layer-version-by-arn --arn 'arn:aws-us-gov:lambda:us-gov-east-1:${{ secrets.AWS_ACCOUNT_ID }}:layer:${{ matrix.layer }}-${{ matrix.arch }}:${{ env.LAYER_VERSION }}' --query 'Content.CodeSha256' --output text)
146
+ SHA=$(jq -r '.Content.CodeSha256' '${{ matrix.layer }}_${{ matrix.arch }}.json')
147
+ test "$REMOTE_SHA" == "$SHA" && echo "SHA OK: ${SHA}" || exit 1
148
+ aws --region us-gov-east-1 lambda get-layer-version-by-arn --arn 'arn:aws-us-gov:lambda:us-gov-east-1:${{ secrets.AWS_ACCOUNT_ID }}:layer:${{ matrix.layer }}-${{ matrix.arch }}:${{ env.LAYER_VERSION }}' --output table
149
+
150
+ copy_west :
151
+ name : Copy (West)
152
+ needs : download
153
+ runs-on : ubuntu-latest
154
+ permissions :
155
+ id-token : write
156
+ contents : read
157
+ strategy :
158
+ matrix :
159
+ layer :
160
+ - AWSLambdaPowertoolsPythonV3-python38
161
+ - AWSLambdaPowertoolsPythonV3-python39
162
+ - AWSLambdaPowertoolsPythonV3-python310
163
+ - AWSLambdaPowertoolsPythonV3-python311
164
+ - AWSLambdaPowertoolsPythonV3-python312
165
+ arch :
166
+ - arm64
167
+ - x86_64
168
+ environment :
169
+ name : GovCloud ${{ inputs.environment }} (West)
170
+ steps :
171
+ - name : Download Zip
172
+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
173
+ with :
174
+ name : ${{ matrix.layer }}_${{ matrix.arch }}.zip
175
+ - name : Download Metadata
176
+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
177
+ with :
178
+ name : ${{ matrix.layer }}_${{ matrix.arch }}.json
179
+ - name : Verify Layer Signature
180
+ run : |
181
+ SHA=$(jq -r '.Content.CodeSha256' '${{ matrix.layer }}_${{ matrix.arch }}.json')
182
+ test "$(openssl dgst -sha256 -binary ${{ matrix.layer }}_${{ matrix.arch }}.zip | openssl enc -base64)" == "$SHA" && echo "SHA OK: ${SHA}" || exit 1
183
+ - name : Configure AWS Credentials
184
+ uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
185
+ with :
186
+ role-to-assume : ${{ secrets.AWS_IAM_ROLE }}
187
+ aws-region : us-gov-west-1
188
+ mask-aws-account-id : true
189
+ - name : Create Layer
190
+ id : create-layer
191
+ run : |
192
+ LAYER_VERSION=$(aws --region us-gov-west-1 lambda publish-layer-version \
193
+ --layer-name ${{ matrix.layer }}-${{ matrix.arch }} \
194
+ --zip-file fileb://./${{ matrix.layer }}_${{ matrix.arch }}.zip \
195
+ --compatible-runtimes "$(jq -r '.CompatibleRuntimes[0]' '${{ matrix.layer }}_${{ matrix.arch }}.json')" \
196
+ --compatible-architectures "$(jq -r '.CompatibleArchitectures[0]' '${{ matrix.layer }}_${{ matrix.arch }}.json')" \
197
+ --license-info "MIT-0" \
198
+ --description "$(jq -r '.Description' '${{ matrix.layer }}_${{ matrix.arch }}.json')" \
199
+ --query 'Version' \
200
+ --output text)
201
+
202
+ echo "LAYER_VERSION=$LAYER_VERSION" >> "$GITHUB_OUTPUT"
203
+
204
+ aws --region us-gov-west-1 lambda add-layer-version-permission \
205
+ --layer-name '${{ matrix.layer }}-${{ matrix.arch }}' \
206
+ --statement-id 'PublicLayer' \
207
+ --action lambda:GetLayerVersion \
208
+ --principal '*' \
209
+ --version-number "$LAYER_VERSION"
210
+ - name : Verify Layer
211
+ env :
212
+ LAYER_VERSION : ${{ steps.create-layer.outputs.LAYER_VERSION }}
213
+ run : |
214
+ REMOTE_SHA=$(aws --region us-gov-west-1 lambda get-layer-version-by-arn --arn 'arn:aws-us-gov:lambda:us-gov-west-1:${{ secrets.AWS_ACCOUNT_ID }}:layer:${{ matrix.layer }}-${{ matrix.arch }}:${{ env.LAYER_VERSION }}' --query 'Content.CodeSha256' --output text)
215
+ SHA=$(jq -r '.Content.CodeSha256' '${{ matrix.layer }}_${{ matrix.arch }}.json')
216
+ test "$REMOTE_SHA" == "$SHA" && echo "SHA OK: ${SHA}" || exit 1
217
+ aws --region us-gov-west-1 lambda get-layer-version-by-arn --arn 'arn:aws-us-gov:lambda:us-gov-west-1:${{ secrets.AWS_ACCOUNT_ID }}:layer:${{ matrix.layer }}-${{ matrix.arch }}:${{ env.LAYER_VERSION }}' --output table
0 commit comments