Skip to content

Commit 65c6d03

Browse files
committed
ci: deploy examples with sam stack
1 parent 99b482e commit 65c6d03

13 files changed

Lines changed: 310 additions & 2076 deletions

File tree

.github/workflows/deploy-examples.yml

Lines changed: 63 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ name: Deploy Python Examples
22

33
on:
44
pull_request:
5-
branches: [ "main", "development"]
6-
paths:
7-
- 'packages/aws-durable-execution-sdk-python/src/**'
8-
- 'packages/aws-durable-execution-sdk-python-examples/**'
9-
- '.github/workflows/deploy-examples.yml'
5+
branches: ["main"]
106
workflow_dispatch:
117

128
env:
@@ -17,28 +13,8 @@ permissions:
1713
contents: read
1814

1915
jobs:
20-
setup:
21-
runs-on: ubuntu-latest
22-
outputs:
23-
examples: ${{ steps.get-examples.outputs.examples }}
24-
steps:
25-
- uses: actions/checkout@v7
26-
27-
- name: Get examples from catalog
28-
id: get-examples
29-
working-directory: ./packages/aws-durable-execution-sdk-python-examples
30-
run: |
31-
echo "examples=$(jq -c '.examples | map(select(.integration == true))' examples-catalog.json)" >> $GITHUB_OUTPUT
32-
3316
integration-test:
34-
needs: setup
3517
runs-on: ubuntu-latest
36-
name: ${{ matrix.example.name }}
37-
strategy:
38-
matrix:
39-
example: ${{ fromJson(needs.setup.outputs.examples) }}
40-
fail-fast: false
41-
4218
steps:
4319
- uses: actions/checkout@v7
4420

@@ -51,86 +27,90 @@ jobs:
5127
if: github.event_name != 'workflow_dispatch' || github.actor != 'nektos/act'
5228
uses: aws-actions/configure-aws-credentials@v6
5329
with:
54-
role-to-assume: "${{ secrets.ACTIONS_INTEGRATION_ROLE_NAME }}"
30+
role-to-assume: "${{ secrets.TEST_ROLE_ARN }}"
5531
role-session-name: pythonTestingLibraryGitHubIntegrationTest
5632
aws-region: ${{ env.AWS_REGION }}
5733

34+
- name: Verify AWS test account
35+
if: github.event_name != 'workflow_dispatch' || github.actor != 'nektos/act'
36+
env:
37+
TEST_ACCOUNT_ID: ${{ secrets.TEST_ACCOUNT_ID }}
38+
run: |
39+
ACTUAL_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
40+
if [ "$ACTUAL_ACCOUNT_ID" != "$TEST_ACCOUNT_ID" ]; then
41+
echo "Expected AWS account $TEST_ACCOUNT_ID but assumed into $ACTUAL_ACCOUNT_ID"
42+
exit 1
43+
fi
44+
echo "Using AWS test account $ACTUAL_ACCOUNT_ID"
45+
5846
- name: Install Hatch
5947
run: pip install hatch
48+
49+
- name: Setup SAM CLI
50+
uses: aws-actions/setup-sam@v2
51+
6052
- name: Build examples
6153
run: |
6254
hatch run -- examples:pip install -e packages/aws-durable-execution-sdk-python packages/aws-durable-execution-sdk-python-otel packages/aws-durable-execution-sdk-python-testing
6355
hatch run examples:build
56+
hatch run examples:generate-sam-template
6457
65-
- name: Deploy Lambda function - ${{ matrix.example.name }}
58+
- name: Deploy all examples with SAM
6659
id: deploy
6760
env:
68-
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
6961
LAMBDA_ENDPOINT: "https://lambda.us-west-2.amazonaws.com"
70-
KMS_KEY_ARN: ${{ secrets.KMS_KEY_ARN }}
7162
run: |
72-
# Build function name
73-
EXAMPLE_NAME_CLEAN=$(echo "${{ matrix.example.name }}" | sed 's/ //g')
7463
if [ "${{ github.event_name }}" = "pull_request" ]; then
75-
FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-Python-PR-${{ github.event.number }}"
64+
STACK_NAME="python-examples-pr-${{ github.event.number }}"
65+
FUNCTION_NAME_PREFIX="PythonPr${{ github.event.number }}-"
7666
else
77-
FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-Python"
67+
STACK_NAME="python-examples"
68+
FUNCTION_NAME_PREFIX="Python-"
7869
fi
79-
80-
# Clean up existing function if present to avoid conflicts
81-
echo "Cleaning up existing function if present..."
82-
aws lambda delete-function \
83-
--function-name "$FUNCTION_NAME" \
84-
--endpoint-url "$LAMBDA_ENDPOINT" \
85-
--region "$AWS_REGION" 2>/dev/null || echo "No existing function to clean up"
86-
87-
# Give AWS time to process the deletion
88-
sleep 5
89-
90-
echo "Deploying ${{ matrix.example.name }} as $FUNCTION_NAME"
91-
hatch run examples:deploy "${{ matrix.example.name }}" --function-name "$FUNCTION_NAME"
92-
93-
# $LATEST is also a qualified version
94-
QUALIFIED_FUNCTION_NAME="${FUNCTION_NAME}:\$LATEST"
95-
96-
# Store both names for later steps
97-
echo "FUNCTION_NAME=$FUNCTION_NAME" >> $GITHUB_ENV
98-
echo "QUALIFIED_FUNCTION_NAME=$QUALIFIED_FUNCTION_NAME" >> $GITHUB_ENV
99-
echo "VERSION=$VERSION" >> $GITHUB_ENV
100-
echo "DEPLOYED_FUNCTION_NAME=$FUNCTION_NAME" >> $GITHUB_OUTPUT
101-
echo "QUALIFIED_FUNCTION_NAME=$QUALIFIED_FUNCTION_NAME" >> $GITHUB_OUTPUT
102-
103-
- name: Run Integration Tests - ${{ matrix.example.name }}
70+
71+
STACK_NAME=$(echo "$STACK_NAME" | tr -cd '[:alnum:]-' | cut -c1-128)
72+
export STACK_NAME FUNCTION_NAME_PREFIX
73+
echo "STACK_NAME=$STACK_NAME" >> $GITHUB_ENV
74+
75+
echo "Building SAM application"
76+
sam build --template-file packages/aws-durable-execution-sdk-python-examples/template.generated.json
77+
78+
echo "Deploying stack $STACK_NAME with function prefix $FUNCTION_NAME_PREFIX"
79+
sam deploy \
80+
--template-file .aws-sam/build/template.yaml \
81+
--stack-name "$STACK_NAME" \
82+
--resolve-s3 \
83+
--capabilities CAPABILITY_IAM \
84+
--no-confirm-changeset \
85+
--no-fail-on-empty-changeset \
86+
--region "$AWS_REGION" \
87+
--parameter-overrides \
88+
FunctionNamePrefix="$FUNCTION_NAME_PREFIX" \
89+
LambdaEndpoint="$LAMBDA_ENDPOINT"
90+
91+
PYTEST_FUNCTION_NAME_MAP=$(
92+
python packages/aws-durable-execution-sdk-python-examples/scripts/generate_function_name_map.py \
93+
--function-name-prefix "$FUNCTION_NAME_PREFIX"
94+
)
95+
96+
echo "PYTEST_FUNCTION_NAME_MAP=$PYTEST_FUNCTION_NAME_MAP" >> $GITHUB_ENV
97+
98+
- name: Run Integration Tests
10499
env:
105100
AWS_REGION: ${{ env.AWS_REGION }}
106101
LAMBDA_ENDPOINT: "https://lambda.us-west-2.amazonaws.com"
107-
QUALIFIED_FUNCTION_NAME: ${{ env.QUALIFIED_FUNCTION_NAME }}
108-
LAMBDA_FUNCTION_TEST_NAME: ${{ matrix.example.name }}
109102
run: |
110-
echo "Running integration tests for ${{ matrix.example.name }}"
111-
echo "Function name: ${{ steps.deploy.outputs.DEPLOYED_FUNCTION_NAME }}"
112-
echo "Qualified function name: ${QUALIFIED_FUNCTION_NAME}"
103+
echo "Running integration tests for all deployed examples"
113104
echo "AWS Region: ${AWS_REGION}"
114105
echo "Lambda Endpoint: ${LAMBDA_ENDPOINT}"
115-
116-
# Convert example name to test name: "Hello World" -> "test_hello_world"
117-
TEST_NAME="test_$(echo "${{ matrix.example.name }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '_')"
118-
echo "Test name: ${TEST_NAME}"
119-
120-
# Run integration tests from repo root
106+
echo "Configured function map: ${PYTEST_FUNCTION_NAME_MAP}"
107+
121108
hatch run test:examples-integration
122109
123-
# Wait for function to be ready
124-
echo "Waiting for function to be active..."
125-
aws lambda wait function-active --function-name "$QUALIFIED_FUNCTION_NAME" --endpoint-url "$LAMBDA_ENDPOINT" --region "$AWS_REGION"
126-
127-
# - name: Cleanup Lambda function
128-
# if: always()
129-
# env:
130-
# LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT_BETA }}
131-
# run: |
132-
# echo "Deleting function: $FUNCTION_NAME"
133-
# aws lambda delete-function \
134-
# --function-name "$FUNCTION_NAME" \
135-
# --endpoint-url "$LAMBDA_ENDPOINT" \
136-
# --region "${{ env.AWS_REGION }}" || echo "Function already deleted or doesn't exist"
110+
- name: Cleanup deployed stack
111+
if: always() && github.event_name == 'pull_request'
112+
run: |
113+
if [ -n "$STACK_NAME" ]; then
114+
echo "Deleting stack: $STACK_NAME"
115+
aws cloudformation delete-stack --stack-name "$STACK_NAME" --region "${{ env.AWS_REGION }}"
116+
fi

.github/workflows/integration-tests.yml

Lines changed: 0 additions & 148 deletions
This file was deleted.

.github/workflows/update-sam-template.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ dist/
3333

3434
**/build/
3535
**/*.zip
36+
.aws-sam/
37+
**/template.generated.json
3638

37-
.env
39+
.env

0 commit comments

Comments
 (0)