Skip to content

docs: update layers version + simplify script #4096

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 29 additions & 88 deletions .github/scripts/update_layer_arn.sh
Original file line number Diff line number Diff line change
@@ -1,98 +1,39 @@
#!/bin/bash

# This script is run during the publish_layer workflow,
# and it is responsible for replacing the layer ARN in our documentation,
# based on the output files generated by CDK.
# This script is run during the publish_layer.yml CI job,
# and it is responsible for replacing the layer ARN in our documentation.
# Our pipeline must generate the same layer number for all commercial regions + gov cloud
# If this doesn't happens, we have an error and we must fix it in the deployment.
#
# see .github/workflows/publish_layer.yml

set -eo pipefail

if [[ $# -ne 1 ]]; then
cat <<EOM
Usage: $(basename $0) cdk-output-dir

cdk-output-dir: directory containing the cdk output files generated when deploying the Layer
EOM
exit 1
fi

CDK_OUTPUT_DIR=$1
DOCS_FILE="docs/getting-started/lambda-layers.md"

# Check if CDK output dir is a directory
if [ ! -d "$CDK_OUTPUT_DIR" ]; then
echo "No $CDK_OUTPUT_DIR directory found, not replacing lambda layer versions"
exit 1
# Get the new version number from the first command-line argument
new_version=$1
if [ -z "$new_version" ]; then
echo "Usage: $0 <new_version>"
exit 1
fi

# Process each file inside the directory
files="$CDK_OUTPUT_DIR/*"
for file in $files; do
echo "[+] Processing: $file"

# Process each line inside the file
lines=$(cat "$file")
for line in $lines; do
echo -e "\t[*] ARN: $line"
# line = arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScript:49

# From the full ARN, extract everything but the version at the end. This prefix
# will later be used to find/replace the ARN on the documentation file.
prefix=$(echo "$line" | cut -d ':' -f 1-7)
# prefix = arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScript

# Now replace the all "prefix"s in the file with the full new Layer ARN (line)
# prefix:\d+ ==> line
# sed doesn't support \d+ in a portable way, so we cheat with (:digit: :digit: *)
sed -i -e "s/$prefix:[[:digit:]][[:digit:]]*/$line/g" $DOCS_FILE

# We use the eu-central-1 layer as the version for all the frameworks (SAM, CDK, SLS, etc)
# We could have used any other region. What's important is the version at the end.

# Examples of strings found in the documentation with pseudo regions:
# arn:aws:lambda:{region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:39
# arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:39
# arn:aws:lambda:${aws:region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:39
# arn:aws:lambda:{env.region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:39
if [[ "$line" == *"eu-central-1"* ]]; then
# These are all the framework pseudo parameters currently found in the docs
for pseudo_region in '{region}' '${AWS::Region}' '${aws:region}' '{aws::region}' '{env.region}' '${Stack.of(this).region}' '${aws.getRegionOutput().name}'; do
prefix_pseudo_region=$(echo "$prefix" | sed "s/eu-central-1/${pseudo_region}/")
# prefix_pseudo_region = arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScript

line_pseudo_region=$(echo "$line" | sed "s/eu-central-1/${pseudo_region}/")
# line_pseudo_region = arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:49

# Replace all the "prefix_pseudo_region"'s in the file
# prefix_pseudo_region:\d+ ==> line_pseudo_region
sed -i -e "s/$prefix_pseudo_region:[[:digit:]][[:digit:]]*/$line_pseudo_region/g" $DOCS_FILE
done
# Find all files with specified extensions in ./docs and ./examples directories
# -type f: only find files (not directories)
# \( ... \): group conditions
# -o: logical OR
# -print0: use null character as separator (handles filenames with spaces)
find ./docs ./examples -type f \( -name "*.md" -o -name "*.ts" -o -name "*.yaml" -o -name "*.txt" -o -name "*.tf" -o -name "*.yml" \) -print0 | while IFS= read -r -d '' file; do
echo "Processing file: $file"

# Use sed to replace the version number in the Lambda layer ARN
# -i: edit files in-place without creating a backup
# -E: use extended regular expressions
# IF TESTING IN MAC, replace `-i` with `-i ''`
# The regex matches the layer name and replaces only the version number at the end
sed -i -E "s/AWSLambdaPowertoolsTypeScriptV2:[0-9]+/AWSLambdaPowertoolsTypeScriptV2:$new_version/g" "$file"
if [ $? -eq 0 ]; then
echo "Updated $file successfully"
grep "arn:aws:lambda:" "$file"
else
echo "Error processing $file"
fi
done
done

echo "[+] Finished processing all commercial regions"

# Now we need to process GovCloud regions
#
# GovCloud layers are not available in the CDK output files, but we know the ARN format and that the version is the same
# as the one in eu-central-1. So we can optimistically update the version of the GovCloud layers in the documentation.
#
# The GovCloud ARNs are (note that the account IDs are different in both):
# arn:aws-us-gov:lambda:us-gov-west-1:165093116878:layer:AWSLambdaPowertoolsTypeScriptV2:25
# arn:aws-us-gov:lambda:us-gov-east-1:165087284144:layer:AWSLambdaPowertoolsTypeScriptV2:25

version=$(echo "$line" | cut -d ':' -f 8) # version = 25
arn_us_gov_west_1="arn:aws-us-gov:lambda:us-gov-west-1:165093116878:layer:AWSLambdaPowertoolsTypeScriptV2:$version"
prefix_us_gov_west_1=$(echo "$arn_us_gov_west_1" | cut -d ':' -f 1-7)
arn_us_gov_east_1="arn:aws-us-gov:lambda:us-gov-east-1:165087284144:layer:AWSLambdaPowertoolsTypeScriptV2:$version"
prefix_us_gov_east_1=$(echo "$arn_us_gov_east_1" | cut -d ':' -f 1-7)
echo -e "\t[*] ARN GovCloud US West 1: $arn_us_gov_west_1"
echo -e "\t[*] ARN GovCloud US East 1: $arn_us_gov_east_1"
# Replace all the "arn_us_gov_west_1"'s in the file
sed -i -e "s/$prefix_us_gov_west_1:[[:digit:]][[:digit:]]*/$arn_us_gov_west_1/g" $DOCS_FILE
# Replace all the "arn_us_gov_east_1"'s in the file
sed -i -e "s/$prefix_us_gov_east_1:[[:digit:]][[:digit:]]*/$arn_us_gov_east_1/g" $DOCS_FILE
echo "[+] Finished processing all GovCloud regions"
echo "[+] Finished processing all regions"
echo "Layer version update attempt completed."
8 changes: 7 additions & 1 deletion .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ name: Make Release
# 5. Update draft release notes with the latest changes and publish the release on GitHub

on:
workflow_dispatch: {}
workflow_dispatch:
inputs:
layer_documentation_version:
description: "Lambda layer version to be updated in our documentation. e.g. if the current layer number is 3, this value must be 4."
type: string
required: true

permissions:
contents: read
Expand Down Expand Up @@ -101,3 +106,4 @@ jobs:
uses: ./.github/workflows/publish_layer.yml
with:
latest_published_version: ${{ needs.publish-npm.outputs.RELEASE_VERSION }}
layer_documentation_version: ${{ inputs.layer_documentation_version }}
18 changes: 9 additions & 9 deletions .github/workflows/publish_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
description: "Latest npm published version to rebuild corresponding layer for, e.g. 1.0.2"
default: "1.0.2"
required: true
layer_documentation_version:
description: "Version to be updated in our documentation. e.g. if the current layer number is 3, this value must be 4."
required: true

workflow_call:
inputs:
Expand All @@ -23,6 +26,10 @@ on:
default: false
type: boolean
required: false
layer_documentation_version:
description: "Version to be updated in our documentation. e.g. if the current layer number is 3, this value must be 4."
required: true
type: string

jobs:
# Build layer by running cdk synth in layer-publisher directory and uploading cdk.out for deployment
Expand Down Expand Up @@ -96,21 +103,14 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.sha }}
- name: Download CDK layer artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: cdk-layer-stack
pattern: cdk-layer-stack-* # merge all Layer artifacts created per region earlier (reusable_deploy_layer_stack.yml; step "Save Layer ARN artifact")
merge-multiple: true
- name: Replace layer versions in documentation
run: |
ls -la cdk-layer-stack/
./.github/scripts/update_layer_arn.sh cdk-layer-stack
./.github/scripts/update_layer_arn.sh ${{ inputs.layer_documentation_version }}
- name: Create PR
id: create-pr
uses: ./.github/actions/create-pr
with:
files: 'docs/getting-started/lambda-layers.md'
temp_branch_prefix: 'ci-layer-docs'
pull_request_title: 'chore(ci): update layer ARN on documentation'
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
70 changes: 35 additions & 35 deletions docs/getting-started/lambda-layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,41 @@ We publish the Lambda Layer for Powertools for AWS Lambda in all commercial regi

| Region | Layer ARN |
| ---------------- | ---------------------------------------------------------------------------------------------------------- |
| `us-east-1` | [arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `us-east-2` | [arn:aws:lambda:us-east-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `us-west-1` | [arn:aws:lambda:us-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `us-west-2` | [arn:aws:lambda:us-west-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-south-1` | [arn:aws:lambda:ap-south-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-south-2` | [arn:aws:lambda:ap-south-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-east-1` | [arn:aws:lambda:ap-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-northeast-1` | [arn:aws:lambda:ap-northeast-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-northeast-2` | [arn:aws:lambda:ap-northeast-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-northeast-3` | [arn:aws:lambda:ap-northeast-3:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-southeast-1` | [arn:aws:lambda:ap-southeast-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-southeast-2` | [arn:aws:lambda:ap-southeast-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-southeast-3` | [arn:aws:lambda:ap-southeast-3:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-southeast-4` | [arn:aws:lambda:ap-southeast-4:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-southeast-5` | [arn:aws:lambda:ap-southeast-5:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ap-southeast-7` | [arn:aws:lambda:ap-southeast-7:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `eu-central-1` | [arn:aws:lambda:eu-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `eu-central-2` | [arn:aws:lambda:eu-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `eu-west-1` | [arn:aws:lambda:eu-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `eu-west-2` | [arn:aws:lambda:eu-west-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `eu-west-3` | [arn:aws:lambda:eu-west-3:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `eu-north-1` | [arn:aws:lambda:eu-north-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `eu-south-1` | [arn:aws:lambda:eu-south-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `eu-south-2` | [arn:aws:lambda:eu-south-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ca-central-1` | [arn:aws:lambda:ca-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `ca-west-1` | [arn:aws:lambda:ca-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `sa-east-1` | [arn:aws:lambda:sa-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `af-south-1` | [arn:aws:lambda:af-south-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `me-south-1` | [arn:aws:lambda:me-south-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `me-central-1` | [arn:aws:lambda:me-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `il-central-1` | [arn:aws:lambda:il-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `mx-central-1` | [arn:aws:lambda:mx-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `us-gov-west-1` | [arn:aws-us-gov:lambda:us-gov-west-1:165093116878:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `us-gov-east-1` | [arn:aws-us-gov:lambda:us-gov-east-1:165087284144:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `cn-north-1` | [arn:aws-aws-cn:lambda:cn-north-1:498634801083:layer:AWSLambdaPowertoolsTypeScriptV2:28](#){: .copyMe} |
| `us-east-1` | [arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `us-east-2` | [arn:aws:lambda:us-east-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `us-west-1` | [arn:aws:lambda:us-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `us-west-2` | [arn:aws:lambda:us-west-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-south-1` | [arn:aws:lambda:ap-south-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-south-2` | [arn:aws:lambda:ap-south-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-east-1` | [arn:aws:lambda:ap-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-northeast-1` | [arn:aws:lambda:ap-northeast-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-northeast-2` | [arn:aws:lambda:ap-northeast-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-northeast-3` | [arn:aws:lambda:ap-northeast-3:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-southeast-1` | [arn:aws:lambda:ap-southeast-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-southeast-2` | [arn:aws:lambda:ap-southeast-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-southeast-3` | [arn:aws:lambda:ap-southeast-3:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-southeast-4` | [arn:aws:lambda:ap-southeast-4:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-southeast-5` | [arn:aws:lambda:ap-southeast-5:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ap-southeast-7` | [arn:aws:lambda:ap-southeast-7:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `eu-central-1` | [arn:aws:lambda:eu-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `eu-central-2` | [arn:aws:lambda:eu-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `eu-west-1` | [arn:aws:lambda:eu-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `eu-west-2` | [arn:aws:lambda:eu-west-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `eu-west-3` | [arn:aws:lambda:eu-west-3:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `eu-north-1` | [arn:aws:lambda:eu-north-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `eu-south-1` | [arn:aws:lambda:eu-south-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `eu-south-2` | [arn:aws:lambda:eu-south-2:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ca-central-1` | [arn:aws:lambda:ca-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `ca-west-1` | [arn:aws:lambda:ca-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `sa-east-1` | [arn:aws:lambda:sa-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `af-south-1` | [arn:aws:lambda:af-south-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `me-south-1` | [arn:aws:lambda:me-south-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `me-central-1` | [arn:aws:lambda:me-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `il-central-1` | [arn:aws:lambda:il-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `mx-central-1` | [arn:aws:lambda:mx-central-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `us-gov-west-1` | [arn:aws-us-gov:lambda:us-gov-west-1:165093116878:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `us-gov-east-1` | [arn:aws-us-gov:lambda:us-gov-east-1:165087284144:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |
| `cn-north-1` | [arn:aws-aws-cn:lambda:cn-north-1:498634801083:layer:AWSLambdaPowertoolsTypeScriptV2:29](#){: .copyMe} |

### Lookup Layer ARN via AWS SSM Parameter Store

Expand Down
2 changes: 1 addition & 1 deletion examples/app/cdk/example-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class PowertoolsExampleStack extends Stack {
'powertools-layer',
`arn:aws:lambda:${
Stack.of(this).region
}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:3`
}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29`
);

// Items table
Expand Down
2 changes: 1 addition & 1 deletion examples/app/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Resources:
- DynamoDBReadPolicy:
TableName: !Ref itemsTable
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:3
- !Sub arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:29
Environment:
Variables:
TABLE_NAME: !Ref itemsTable
Expand Down
Loading