Skip to content

Commit bb2259b

Browse files
Refactoring publish SAR
1 parent cd0f41f commit bb2259b

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

.github/workflows/publish_v3_layer.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,10 @@ jobs:
194194
contents: read
195195
pull-requests: none
196196
pages: none
197-
uses: ./.github/workflows/reusable_deploy_v2_sar.yml
197+
uses: ./.github/workflows/reusable_deploy_v3_sar.yml
198198
secrets: inherit
199199
with:
200200
stage: "BETA"
201-
artefact-name: "cdk-layer-artefact"
202201
environment: "layer-beta"
203202
package-version: ${{ inputs.latest_published_version }}
204203
source_code_artifact_name: ${{ inputs.source_code_artifact_name }}
@@ -213,11 +212,10 @@ jobs:
213212
contents: read
214213
pull-requests: none
215214
pages: none
216-
uses: ./.github/workflows/reusable_deploy_v2_sar.yml
215+
uses: ./.github/workflows/reusable_deploy_v3_sar.yml
217216
secrets: inherit
218217
with:
219218
stage: "PROD"
220-
artefact-name: "cdk-layer-artefact"
221219
environment: "layer-prod"
222220
package-version: ${{ inputs.latest_published_version }}
223221
source_code_artifact_name: ${{ inputs.source_code_artifact_name }}

.github/workflows/reusable_deploy_v3_sar.yml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ name: Deploy V3 SAR
44
#
55
# 1. This workflow starts after the layer artifact is produced on `publish_v3_layer`
66
# 2. We use the same layer artifact to ensure the SAR app is consistent with the published Lambda Layer
7-
# 3. We publish the SAR for both x86_64 and arm64 (see `matrix` section)
7+
# 3. We publish the SAR for 3.8 to 3.12 Python runtime and both x86_64 and arm64 (see `matrix` section)
88
# 4. We use `sam package` and `sam publish` to publish the SAR app
99
# 5. We remove the previous Canary stack (if present) and deploy a new one to test the SAR App. We retain the Canary in the account for debugging purposes
1010
# 6. Finally the published SAR app is made public on the PROD environment
1111

1212
# USAGE
1313
#
14-
# NOTE: meant to be used with ./.github/workflows/publish_v2_layer.yml
14+
# NOTE: meant to be used with ./.github/workflows/publish_v3_layer.yml
1515
#
1616
# sar-beta:
1717
# needs: build-layer
@@ -25,7 +25,6 @@ name: Deploy V3 SAR
2525
# secrets: inherit
2626
# with:
2727
# stage: "BETA"
28-
# artefact-name: "cdk-layer-artefact"
2928
# environment: "layer-beta"
3029
# package-version: ${{ inputs.latest_published_version }}
3130
# source_code_artifact_name: ${{ inputs.source_code_artifact_name }}
@@ -36,10 +35,10 @@ permissions:
3635
contents: read
3736

3837
env:
39-
NODE_VERSION: 16.12
38+
NODE_VERSION: 18.20.4
4039
AWS_REGION: eu-west-1
41-
SAR_NAME: aws-lambda-powertools-python-layer
42-
TEST_STACK_NAME: serverlessrepo-v2-powertools-layer-test-stack
40+
SAR_NAME: aws-lambda-powertools-python-layer # PROBLEM - WE NEED TO TALK
41+
TEST_STACK_NAME: serverlessrepo-v3-powertools-layer-test-stack
4342
RELEASE_COMMIT: ${{ github.sha }} # it gets propagated from the caller for security reasons
4443

4544
on:
@@ -49,10 +48,6 @@ on:
4948
description: "Deployment stage (BETA, PROD)"
5049
required: true
5150
type: string
52-
artefact-name:
53-
description: "CDK Layer Artefact name to download"
54-
required: true
55-
type: string
5651
package-version:
5752
description: "The version of the package to deploy"
5853
required: true
@@ -77,6 +72,7 @@ jobs:
7772
strategy:
7873
matrix:
7974
architecture: ["x86_64", "arm64"]
75+
python-version: ["3.8","3.9","3.10","3.11","3.12"]
8076
steps:
8177
- name: checkout
8278
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
@@ -117,14 +113,20 @@ jobs:
117113
- name: Download artifact
118114
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
119115
with:
120-
name: ${{ inputs.artefact-name }}
116+
name: cdk-layer-artifact-py${{ matrix.python-version }}
121117
- name: Unzip artefact
122-
run: unzip cdk.out.zip
118+
run: unzip cdk.py${{ matrix.python-version }}.out.zip
119+
- name: normalize Python Version
120+
run: |
121+
PYTHON_VERSION=$(echo ${{ matrix.python-version }} | tr -d '.')
122+
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> "$GITHUB_ENV"
123123
- name: Configure SAR name
124124
run: |
125125
if [[ "${{ inputs.stage }}" == "BETA" ]]; then
126126
SAR_NAME="test-${SAR_NAME}"
127127
fi
128+
ARCH_NAME=$(echo ${{ matrix.architecture }} | tr -d '_')
129+
SAR_NAME="${SAR_NAME}-python${{env.PYTHON_VERSION}}-${ARCH_NAME}"
128130
echo SAR_NAME="${SAR_NAME}" >> "$GITHUB_ENV"
129131
- name: Adds arm64 suffix to SAR name
130132
if: ${{ matrix.architecture == 'arm64' }}
@@ -142,31 +144,33 @@ jobs:
142144
run: |
143145
# From the generated LayerStack cdk.out artifact, find the layer asset path for the correct architecture.
144146
# We'll use this as the source directory of our SAR. This way we are re-using the same layer asset for our SAR.
145-
asset=$(jq -jc '.Resources[] | select(.Properties.CompatibleArchitectures == ["${{ matrix.architecture }}"]) | .Metadata."aws:asset:path"' cdk.out/LayerV2Stack.template.json)
147+
PYTHON_VERSION=$(echo ${{ matrix.python-version }} | tr -d '.')
148+
asset=$(jq -jc '.Resources[] | select(.Properties.CompatibleArchitectures == ["${{ matrix.architecture }}"]) | .Metadata."aws:asset:path"' "cdk.out/LayerV3Stack-${PYTHON_VERSION}.template.json")
146149
147150
# fill in the SAR SAM template
148151
sed \
149152
-e "s|<VERSION>|${VERSION}|g" \
150153
-e "s/<SAR_APP_NAME>/${{ env.SAR_NAME }}/g" \
151154
-e "s|<LAYER_CONTENT_PATH>|./cdk.out/$asset|g" \
155+
-e "s|<PYTHON_RUNTIME>|${{ matrix.python-version }}|g" \
156+
-e "s|<ARCHITECTURE>|${{ matrix.architecture }}|g" \
152157
layer/sar/template.txt > template.yml
153158
154159
# SAR needs a README and a LICENSE, so just copy the ones from the repo
155160
cp README.md LICENSE "./cdk.out/$asset/"
156-
157-
# Debug purposes
158-
cat template.yml
159161
- name: Deploy SAR
160162
run: |
163+
# Debug purposes
164+
cat template.yml
165+
161166
# Package the SAR to our SAR S3 bucket, and publish it
162167
sam package --template-file template.yml --output-template-file packaged.yml --s3-bucket ${{ secrets.AWS_SAR_S3_BUCKET }}
163168
sam publish --template packaged.yml --region "$AWS_REGION"
164169
- name: Deploy BETA canary
165170
if: ${{ inputs.stage == 'BETA' }}
166171
run: |
167-
if [[ "${{ matrix.architecture }}" == "arm64" ]]; then
168-
TEST_STACK_NAME="${TEST_STACK_NAME}-arm64"
169-
fi
172+
ARCH_NAME=$(echo ${{ matrix.architecture }} | tr -d '_')
173+
TEST_STACK_NAME="${TEST_STACK_NAME}-python${{env.PYTHON_VERSION}}-${ARCH_NAME}"
170174
171175
echo "Check if stack does not exist"
172176
stack_exists=$(aws cloudformation list-stacks --query "StackSummaries[?(StackName == '$TEST_STACK_NAME' && StackStatus == 'CREATE_COMPLETE')].{StackId:StackId, StackName:StackName, CreationTime:CreationTime, StackStatus:StackStatus}" --output text)

layer_v3/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
POWERTOOLS_VERSION: str = app.node.try_get_context("version")
1111
PYTHON_VERSION: str = app.node.try_get_context("pythonVersion")
1212
PYTHON_VERSION_NORMALIZED = PYTHON_VERSION.replace(".", "")
13-
SSM_PARAM_LAYER_ARN: str = "/layers/powertools-layer-v3-arn-{PYTHON_VERSION_NORMALIZED}"
14-
SSM_PARAM_LAYER_ARM64_ARN: str = "/layers/powertools-layer-v3-arm64-arn-{PYTHON_VERSION_NORMALIZED}"
13+
SSM_PARAM_LAYER_ARN: str = f"/layers/powertools-layer-v3-{PYTHON_VERSION_NORMALIZED}-x86-arn"
14+
SSM_PARAM_LAYER_ARM64_ARN: str = f"/layers/powertools-layer-v3-{PYTHON_VERSION_NORMALIZED}-arm64-arn"
1515

1616
# Validate context variables
1717
if not PYTHON_VERSION:

layer_v3/layer/layer_stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def __init__(
8080
super().__init__(scope, construct_id, **kwargs)
8181

8282
python_version_normalized = python_version.replace(".", "")
83-
layer_name_x86 = f"AWSLambdaPowertoolsPythonV3-{python_version_normalized}"
84-
layer_name_arm64 = f"AWSLambdaPowertoolsPythonV3-Arm64-{python_version_normalized}"
83+
layer_name_x86 = f"AWSLambdaPowertoolsPythonV3-{python_version_normalized}-x86"
84+
layer_name_arm64 = f"AWSLambdaPowertoolsPythonV3-{python_version_normalized}-arm64"
8585

8686
has_arm64_support = CfnParameter(
8787
self,

layer_v3/sar/template.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,30 @@ AWSTemplateFormatVersion: '2010-09-09'
33
Metadata:
44
AWS::ServerlessRepo::Application:
55
Name: <SAR_APP_NAME>
6-
Description: "AWS Lambda Layer for aws-lambda-powertools"
6+
Description: "AWS Lambda Layer for Powertools for AWS Lambda V3 [<ARCHITECTURE>] with python <PYTHON_RUNTIME>"
77
Author: AWS
88
SpdxLicenseId: Apache-2.0
99
LicenseUrl: <LAYER_CONTENT_PATH>/LICENSE
1010
ReadmeUrl: <LAYER_CONTENT_PATH>/README.md
11-
Labels: ['layer','lambda','powertools','python', 'aws']
11+
Labels: ['layer','lambda','powertools','python', 'aws', '<ARCHITECTURE>']
1212
HomePageUrl: https://github.com/aws-powertools/powertools-lambda-python
1313
SemanticVersion: <VERSION>
1414
SourceCodeUrl: https://github.com/aws-powertools/powertools-lambda-python
1515

1616
Transform: AWS::Serverless-2016-10-31
17-
Description: AWS Lambda Layer for aws-lambda-powertools with python 3.12, 3.11, 3.10, 3.9 or 3.8
17+
Description: AWS Lambda Layer for Powertools for AWS Lambda V3 [<ARCHITECTURE>] with python <PYTHON_RUNTIME>
1818

1919
Resources:
2020
LambdaLayer:
2121
Type: AWS::Serverless::LayerVersion
2222
Properties:
23-
Description: "AWS Lambda Layer for aws-lambda-powertools version <VERSION>"
23+
Description: "AWS Lambda Layer for Powertools for AWS Lambda V3 [<ARCHITECTURE>] - python <PYTHON_RUNTIME> - version <VERSION>"
2424
LayerName: <SAR_APP_NAME>
2525
ContentUri: <LAYER_CONTENT_PATH>
26+
CompatibleArchitectures:
27+
- <ARCHITECTURE>
2628
CompatibleRuntimes:
27-
- python3.12
28-
- python3.11
29-
- python3.10
30-
- python3.9
31-
- python3.8
29+
- python<PYTHON_RUNTIME>
3230
LicenseInfo: 'Available under the Apache-2.0 license.'
3331
RetentionPolicy: Retain
3432

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "aws_lambda_powertools"
3-
version = "2.38.1"
3+
version = "3.0.0"
44
description = "Powertools for AWS Lambda (Python) is a developer toolkit to implement Serverless best practices and increase developer velocity."
55
authors = ["Amazon Web Services"]
66
include = ["aws_lambda_powertools/py.typed", "THIRD-PARTY-LICENSES"]

0 commit comments

Comments
 (0)