Skip to content

Commit 00edfd0

Browse files
committed
ci: deploy examples with sam stack
1 parent 99b482e commit 00edfd0

13 files changed

Lines changed: 297 additions & 2075 deletions

File tree

.github/workflows/deploy-examples.yml

Lines changed: 50 additions & 82 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

@@ -57,80 +33,72 @@ jobs:
5733

5834
- name: Install Hatch
5935
run: pip install hatch
36+
37+
- name: Setup SAM CLI
38+
uses: aws-actions/setup-sam@v2
39+
6040
- name: Build examples
6141
run: |
6242
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
6343
hatch run examples:build
44+
hatch run examples:generate-sam-template
6445
65-
- name: Deploy Lambda function - ${{ matrix.example.name }}
46+
- name: Deploy all examples with SAM
6647
id: deploy
6748
env:
68-
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
6949
LAMBDA_ENDPOINT: "https://lambda.us-west-2.amazonaws.com"
70-
KMS_KEY_ARN: ${{ secrets.KMS_KEY_ARN }}
7150
run: |
72-
# Build function name
73-
EXAMPLE_NAME_CLEAN=$(echo "${{ matrix.example.name }}" | sed 's/ //g')
7451
if [ "${{ github.event_name }}" = "pull_request" ]; then
75-
FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-Python-PR-${{ github.event.number }}"
52+
STACK_NAME="python-examples-pr-${{ github.event.number }}"
53+
FUNCTION_NAME_PREFIX="PythonPr${{ github.event.number }}-"
7654
else
77-
FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-Python"
55+
STACK_NAME="python-examples"
56+
FUNCTION_NAME_PREFIX="Python-"
7857
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 }}
58+
59+
STACK_NAME=$(echo "$STACK_NAME" | tr -cd '[:alnum:]-' | cut -c1-128)
60+
export STACK_NAME FUNCTION_NAME_PREFIX
61+
echo "STACK_NAME=$STACK_NAME" >> $GITHUB_ENV
62+
63+
echo "Building SAM application"
64+
sam build --template-file packages/aws-durable-execution-sdk-python-examples/template.generated.json
65+
66+
echo "Deploying stack $STACK_NAME with function prefix $FUNCTION_NAME_PREFIX"
67+
sam deploy \
68+
--template-file .aws-sam/build/template.yaml \
69+
--stack-name "$STACK_NAME" \
70+
--resolve-s3 \
71+
--capabilities CAPABILITY_IAM \
72+
--no-confirm-changeset \
73+
--no-fail-on-empty-changeset \
74+
--region "$AWS_REGION" \
75+
--parameter-overrides \
76+
FunctionNamePrefix="$FUNCTION_NAME_PREFIX" \
77+
LambdaEndpoint="$LAMBDA_ENDPOINT"
78+
79+
PYTEST_FUNCTION_NAME_MAP=$(
80+
python packages/aws-durable-execution-sdk-python-examples/scripts/generate_function_name_map.py \
81+
--function-name-prefix "$FUNCTION_NAME_PREFIX"
82+
)
83+
84+
echo "PYTEST_FUNCTION_NAME_MAP=$PYTEST_FUNCTION_NAME_MAP" >> $GITHUB_ENV
85+
86+
- name: Run Integration Tests
10487
env:
10588
AWS_REGION: ${{ env.AWS_REGION }}
10689
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 }}
10990
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}"
91+
echo "Running integration tests for all deployed examples"
11392
echo "AWS Region: ${AWS_REGION}"
11493
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
94+
echo "Configured function map: ${PYTEST_FUNCTION_NAME_MAP}"
95+
12196
hatch run test:examples-integration
12297
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"
98+
- name: Cleanup deployed stack
99+
if: always() && github.event_name == 'pull_request'
100+
run: |
101+
if [ -n "$STACK_NAME" ]; then
102+
echo "Deleting stack: $STACK_NAME"
103+
aws cloudformation delete-stack --stack-name "$STACK_NAME" --region "${{ env.AWS_REGION }}"
104+
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)