Skip to content

docs(homepage): auto-update Layer ARN on every release #1610

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 12 commits into from
Oct 18, 2022
4 changes: 2 additions & 2 deletions .github/workflows/reusable_deploy_v2_layer_stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ jobs:
name: cdk-layer-stack
path: cdk-layer-stack*

publish_v2_layer_arn:
update_v2_layer_arn_docs:
permissions:
contents: write
uses: ./.github/workflows/reusable_publish_v2_layer_arn.yml
uses: ./.github/workflows/reusable_update_v2_layer_arn_docs.yml
with:
latest_published_version: ${{ inputs.latest_published_version }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish V2 Layer ARN
name: Update V2 Layer ARN Docs

on:
workflow_call:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
run: |
HAS_CHANGE=$(git status --porcelain)
test -z "${HAS_CHANGE}" && echo "Nothing to update" && exit 0
git add CHANGELOG.md
git add docs/index.md
git commit -m "chore: update v2 layer ARN on documentation"
git pull origin "${BRANCH}" # prevents concurrent branch update failing push
git push origin HEAD:refs/heads/"${BRANCH}"
Expand All @@ -57,4 +57,4 @@ jobs:
uses: ./.github/workflows/reusable_publish_docs.yml
with:
version: ${{ inputs.latest_published_version }}
alias: alpha
alias: latest
27 changes: 11 additions & 16 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
| `us-west-1` | [arn:aws:lambda:us-west-1:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:1](#){: .copyMe}:clipboard: |
| `us-west-2` | [arn:aws:lambda:us-west-2:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:1](#){: .copyMe}:clipboard: |

??? question "Can't find our Lambda Layer for your preferred AWS region?"
You can use [Serverless Application Repository (SAR)](#sar) method, our [CDK Layer Construct](https://github.com/aws-samples/cdk-lambda-powertools-python-layer){target="_blank"}, or PyPi like you normally would for any other library.

Please do file a feature request with the region you'd want us to prioritize making our Lambda Layer available.

=== "x86_64"

=== "SAM"
Expand Down Expand Up @@ -398,8 +393,8 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
SemanticVersion: 1.30.0 # change to latest semantic version available in SAR
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-v2
SemanticVersion: 2.0.0 # change to latest semantic version available in SAR

MyLambdaFunction:
Type: AWS::Serverless::Function
Expand All @@ -425,9 +420,9 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-v2
# Find latest from github.com/awslabs/aws-lambda-powertools-python/releases
SemanticVersion: 1.30.0
SemanticVersion: 2.0.0
```

=== "CDK"
Expand All @@ -437,8 +432,8 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,

POWERTOOLS_BASE_NAME = 'AWSLambdaPowertools'
# Find latest from github.com/awslabs/aws-lambda-powertools-python/releases
POWERTOOLS_VER = '1.30.0'
POWERTOOLS_ARN = 'arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer'
POWERTOOLS_VER = '2.0.0'
POWERTOOLS_ARN = 'arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-v2'

class SampleApp(core.Construct):

Expand Down Expand Up @@ -495,13 +490,13 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
}

data "aws_serverlessapplicationrepository_application" "sar_app" {
application_id = "arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer"
application_id = "arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-v2"
semantic_version = var.aws_powertools_version
}

variable "aws_powertools_version" {
type = string
default = "1.30.0"
default = "2.0.0"
description = "The AWS Powertools release version"
}

Expand Down Expand Up @@ -558,7 +553,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
- serverlessrepo:GetCloudFormationTemplate
Resource:
# this is arn of the powertools SAR app
- arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
- arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-v2
- Sid: S3AccessLayer
Effect: Allow
Action:
Expand All @@ -575,7 +570,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
- lambda:PublishLayerVersion
- lambda:GetLayerVersion
Resource:
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:aws-lambda-powertools-python-layer*
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:aws-lambda-powertools-python-layer-v2*
Roles:
- Ref: "PowertoolsLayerIamRole"
```
Expand All @@ -584,7 +579,7 @@ You can fetch available versions via SAR ListApplicationVersions API:

```bash title="AWS CLI example"
aws serverlessrepo list-application-versions \
--application-id arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
--application-id arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-v2
```

## Quick getting started
Expand Down
2 changes: 1 addition & 1 deletion docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.md-grid {
max-width: 81vw
max-width: 90vw
}

.highlight .hll {
Expand Down
30 changes: 23 additions & 7 deletions layer/scripts/update_layer_arn.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# This script is run during the reusable_publish_v2_layer_arn CI job,
# This script is run during the reusable_update_v2_layer_arn_docs CI job,
# and it is responsible for replacing the layer ARN in our documentation,
# based on the output files generated by CDK when deploying to each region.
# based on the output files generated by CDK when deploying to each pseudo_region.
#
# see .github/workflows/reusable_deploy_v2_layer_stack.yml

Expand Down Expand Up @@ -36,22 +36,38 @@ do
for line in $lines
do
echo -e "\t- $line"
# line = arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPython: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:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPython

# Sed doesn't support \d+ in a portable way, so we cheat with (:digit: :digit: *)
# 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/index.md

# We use the eu-central-1 layer as the canonical version for all the generic examples
# 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}:017000801446:layer:AWSLambdaPowertoolsPython:39
# arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPython:39
# arn:aws:lambda:${aws:region}:017000801446:layer:AWSLambdaPowertoolsPython:39
# arn:aws:lambda:{env.region}:017000801446:layer:AWSLambdaPowertoolsPython:39
if [[ "$line" == *"eu-central-1"* ]]; then
for region in '{region}' '${AWS::Region}' '${aws:region}' '{env.region}'
# These are all the framework pseudo parameters currently found in the docs
for pseudo_region in '{region}' '${AWS::Region}' '${aws:region}' '{env.region}'
do
generic_prefix=$(echo "$prefix" | sed "s/eu-central-1/${region}/")
generic_line=$(echo "$line" | sed "s/eu-central-1/${region}/")
generic_prefix=$(echo "$prefix" | sed "s/eu-central-1/${pseudo_region}/")
# generic_prefix = arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPython

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

# Replace all the "generic_prefix"'s in the file
# generic_prefix:\d+ ==> generic_line
sed -i '' -e "s/$generic_prefix:[[:digit:]][[:digit:]]*/$generic_line/g" docs/index.md
done
fi
Expand Down