generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 181
improv(ci): automated the Gamma/Prod deployment to China/GovCloud regions #4864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+156
−119
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| name: Copy Layer | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| environment: | ||
| required: true | ||
| type: string | ||
| partition: | ||
| required: true | ||
| type: string | ||
| arn_partition: | ||
| required: true | ||
| type: string | ||
| regions: | ||
| required: true | ||
| type: string | ||
| aud: | ||
| required: true | ||
| type: string | ||
|
|
||
| jobs: | ||
| # This job deploys the layer to all regions in the target partition using a matrix strategy. It performs integrity checks, publishes the layer, sets public permissions, and validates deployment. | ||
| deploy: | ||
| name: Deploy ${{ inputs.partition }} - ${{ inputs.environment }} | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| environment: ${{ inputs.partition }} ${{ inputs.environment }} | ||
| strategy: | ||
| matrix: | ||
| region: ${{ fromJson(inputs.regions) }} | ||
| steps: | ||
| - name: Download Zip | ||
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | ||
| with: | ||
| name: AWSLambdaPowertoolsTypeScriptV2.zip | ||
|
|
||
| - name: Download Metadata | ||
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | ||
| with: | ||
| name: AWSLambdaPowertoolsTypeScriptV2.json | ||
|
|
||
| - name: Verify Layer Signature | ||
| run: | | ||
| SHA=$(jq -r '.Content.CodeSha256' 'AWSLambdaPowertoolsTypeScriptV2.json') | ||
| test "$(openssl dgst -sha256 -binary AWSLambdaPowertoolsTypeScriptV2.zip | openssl enc -base64)" == "$SHA" && echo "SHA OK: ${SHA}" || exit 1 | ||
|
|
||
| - id: transform | ||
| run: | | ||
| echo 'CONVERTED_REGION=${{ matrix.region }}' | tr 'a-z\-' 'A-Z_' >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Configure AWS Credentials | ||
| uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 # v5.1.1 | ||
| with: | ||
| role-to-assume: ${{ secrets[format('IAM_ROLE_{0}', steps.transform.outputs.CONVERTED_REGION)] }} | ||
| aws-region: ${{ matrix.region }} | ||
| mask-aws-account-id: true | ||
| audience: ${{ inputs.aud }} | ||
|
|
||
| - name: Create Layer | ||
| id: create-layer | ||
| run: | | ||
| set -euo pipefail | ||
| cat AWSLambdaPowertoolsTypeScriptV2.json | jq '{"LayerName": "AWSLambdaPowertoolsTypeScriptV2", "Description": .Description, "CompatibleRuntimes": .CompatibleRuntimes, "LicenseInfo": .LicenseInfo}' > input.json | ||
|
|
||
| LAYER_VERSION=$(aws --region "${{ matrix.region }}" lambda publish-layer-version \ | ||
| --zip-file fileb://./AWSLambdaPowertoolsTypeScriptV2.zip \ | ||
| --cli-input-json file://./input.json \ | ||
| --query 'Version' \ | ||
| --output text) | ||
|
|
||
| echo "LAYER_VERSION=$LAYER_VERSION" >> "$GITHUB_OUTPUT" | ||
|
|
||
| aws --region "${{ matrix.region }}" lambda add-layer-version-permission \ | ||
| --layer-name 'AWSLambdaPowertoolsTypeScriptV2' \ | ||
| --statement-id 'PublicLayer' \ | ||
| --action lambda:GetLayerVersion \ | ||
| --principal '*' \ | ||
| --version-number "$LAYER_VERSION" | ||
|
|
||
| # This step retrieves the newly deployed layer metadata and compares it against the original source layer: | ||
| # 1. SHA256 hash verification - ensures the layer content is identical to the source | ||
| # 2. Description validation - confirms the version number in the description matches the source | ||
| # 3. Layer Version number verification - validates that the layer version numbers match between source and target | ||
| # 4. Tabular comparison output - displays side-by-side comparison of key layer properties | ||
| - name: Verify Layer | ||
| env: | ||
| LAYER_VERSION: ${{ steps.create-layer.outputs.LAYER_VERSION }} | ||
| ENVIRONMENT: ${{ inputs.environment }} | ||
| PARTITION: ${{ inputs.arn_partition }} | ||
| run: | | ||
| set -euo pipefail | ||
| export layer_output="AWSLambdaPowertoolsTypeScriptV2-${{ matrix.region }}.json" | ||
| # Dynamic secret access is safe here - secrets are scoped per environment | ||
| aws --region "${{ matrix.region }}" lambda get-layer-version-by-arn --arn "arn:${PARTITION}:lambda:${{ matrix.region }}:${{ secrets[format('AWS_ACCOUNT_{0}', steps.transform.outputs.CONVERTED_REGION)] }}:layer:AWSLambdaPowertoolsTypeScriptV2:${LAYER_VERSION}" > "$layer_output" | ||
|
||
|
|
||
| REMOTE_SHA=$(jq -r '.Content.CodeSha256' "$layer_output") | ||
| LOCAL_SHA=$(jq -r '.Content.CodeSha256' AWSLambdaPowertoolsTypeScriptV2.json) | ||
| test "$REMOTE_SHA" == "$LOCAL_SHA" && echo "SHA OK: ${LOCAL_SHA}" || exit 1 | ||
|
|
||
| REMOTE_DESCRIPTION=$(jq -r '.Description' "$layer_output") | ||
| LOCAL_DESCRIPTION=$(jq -r '.Description' AWSLambdaPowertoolsTypeScriptV2.json) | ||
| test "$REMOTE_DESCRIPTION" == "$LOCAL_DESCRIPTION" && echo "Description OK: ${LOCAL_DESCRIPTION}" || exit 1 | ||
|
|
||
| if [ "$ENVIRONMENT" == "Prod" ]; then | ||
| REMOTE_LAYER_VERSION=$(jq -r '.LayerVersionArn' "$layer_output" | sed 's/.*://') | ||
| LOCAL_LAYER_VERSION=$(jq -r '.LayerVersionArn' AWSLambdaPowertoolsTypeScriptV2.json | sed 's/.*://') | ||
| test "$REMOTE_LAYER_VERSION" == "$LOCAL_LAYER_VERSION" && echo "Layer Version number OK: ${LOCAL_LAYER_VERSION}" || exit 1 | ||
| fi | ||
|
|
||
| jq -s -r '["Layer Arn", "Runtimes", "Version", "Description", "SHA256"], ([.[0], .[1]] | .[] | [.LayerArn, (.CompatibleRuntimes | join("/")), .Version, .Description, .Content.CodeSha256]) |@tsv' AWSLambdaPowertoolsTypeScriptV2.json "$layer_output" | column -t -s $'\t' | ||
|
|
||
| - name: Store Metadata - ${{ matrix.region }} | ||
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | ||
| with: | ||
| name: AWSLambdaPowertoolsTypeScriptV2-${{ matrix.region }}.json | ||
| path: AWSLambdaPowertoolsTypeScriptV2-${{ matrix.region }}.json | ||
| retention-days: 1 | ||
| if-no-files-found: error | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.