Skip to content

Commit 6afda40

Browse files
committed
move examples from testing library
1 parent 72b5336 commit 6afda40

119 files changed

Lines changed: 7414 additions & 44 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Deploy Python Examples
2+
3+
on:
4+
pull_request:
5+
branches: [ "main", "development"]
6+
paths:
7+
- 'src/aws_durable_execution_sdk_python/**'
8+
- 'examples/**'
9+
- '.github/workflows/deploy-examples.yml'
10+
workflow_dispatch:
11+
12+
env:
13+
AWS_REGION: us-west-2
14+
15+
permissions:
16+
id-token: write
17+
contents: read
18+
19+
jobs:
20+
setup:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
examples: ${{ steps.get-examples.outputs.examples }}
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Get examples from catalog
28+
id: get-examples
29+
working-directory: ./examples
30+
run: |
31+
echo "examples=$(jq -c '.examples | map(select(.integration == true))' examples-catalog.json)" >> $GITHUB_OUTPUT
32+
33+
integration-test:
34+
needs: setup
35+
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+
42+
steps:
43+
- uses: actions/checkout@v4
44+
45+
- name: Setup SSH Agent
46+
uses: webfactory/ssh-agent@dc588b651fe13675774614f8e6a936a468676387 # v0.9.0
47+
with:
48+
ssh-private-key: ${{ secrets.SDK_KEY }}
49+
50+
- name: Setup Python
51+
uses: actions/setup-python@v4
52+
with:
53+
python-version: '3.13'
54+
55+
- name: Configure AWS credentials
56+
if: github.event_name != 'workflow_dispatch' || github.actor != 'nektos/act'
57+
uses: aws-actions/configure-aws-credentials@v4
58+
with:
59+
role-to-assume: "${{ secrets.ACTIONS_INTEGRATION_ROLE_NAME }}"
60+
role-session-name: pythonTestingLibraryGitHubIntegrationTest
61+
aws-region: ${{ env.AWS_REGION }}
62+
63+
- name: Install Hatch
64+
run: pip install hatch
65+
- name: Build examples
66+
run: hatch run examples:build
67+
68+
- name: Deploy Lambda function - ${{ matrix.example.name }}
69+
id: deploy
70+
env:
71+
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
72+
LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT_BETA }}
73+
KMS_KEY_ARN: ${{ secrets.KMS_KEY_ARN }}
74+
run: |
75+
# Build function name
76+
EXAMPLE_NAME_CLEAN=$(echo "${{ matrix.example.name }}" | sed 's/ //g')
77+
if [ "${{ github.event_name }}" = "pull_request" ]; then
78+
FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-Python-PR-${{ github.event.number }}"
79+
else
80+
FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-Python"
81+
fi
82+
83+
# Clean up existing function if present to avoid conflicts
84+
echo "Cleaning up existing function if present..."
85+
aws lambda delete-function \
86+
--function-name "$FUNCTION_NAME" \
87+
--endpoint-url "$LAMBDA_ENDPOINT" \
88+
--region "$AWS_REGION" 2>/dev/null || echo "No existing function to clean up"
89+
90+
# Give AWS time to process the deletion
91+
sleep 5
92+
93+
echo "Deploying ${{ matrix.example.name }} as $FUNCTION_NAME"
94+
hatch run examples:deploy "${{ matrix.example.name }}" --function-name "$FUNCTION_NAME"
95+
96+
# $LATEST is also a qualified version
97+
QUALIFIED_FUNCTION_NAME="${FUNCTION_NAME}:\$LATEST"
98+
99+
# Store both names for later steps
100+
echo "FUNCTION_NAME=$FUNCTION_NAME" >> $GITHUB_ENV
101+
echo "QUALIFIED_FUNCTION_NAME=$QUALIFIED_FUNCTION_NAME" >> $GITHUB_ENV
102+
echo "VERSION=$VERSION" >> $GITHUB_ENV
103+
echo "DEPLOYED_FUNCTION_NAME=$FUNCTION_NAME" >> $GITHUB_OUTPUT
104+
echo "QUALIFIED_FUNCTION_NAME=$QUALIFIED_FUNCTION_NAME" >> $GITHUB_OUTPUT
105+
106+
- name: Run Integration Tests - ${{ matrix.example.name }}
107+
env:
108+
AWS_REGION: ${{ env.AWS_REGION }}
109+
LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT_BETA }}
110+
QUALIFIED_FUNCTION_NAME: ${{ env.QUALIFIED_FUNCTION_NAME }}
111+
LAMBDA_FUNCTION_TEST_NAME: ${{ matrix.example.name }}
112+
run: |
113+
echo "Running integration tests for ${{ matrix.example.name }}"
114+
echo "Function name: ${{ steps.deploy.outputs.DEPLOYED_FUNCTION_NAME }}"
115+
echo "Qualified function name: ${QUALIFIED_FUNCTION_NAME}"
116+
echo "AWS Region: ${AWS_REGION}"
117+
echo "Lambda Endpoint: ${LAMBDA_ENDPOINT}"
118+
119+
# Convert example name to test name: "Hello World" -> "test_hello_world"
120+
TEST_NAME="test_$(echo "${{ matrix.example.name }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '_')"
121+
echo "Test name: ${TEST_NAME}"
122+
123+
# Run integration tests
124+
hatch run test:examples-integration
125+
126+
# Wait for function to be ready
127+
echo "Waiting for function to be active..."
128+
aws lambda wait function-active --function-name "$QUALIFIED_FUNCTION_NAME" --endpoint-url "$LAMBDA_ENDPOINT" --region "$AWS_REGION"
129+
130+
# - name: Cleanup Lambda function
131+
# if: always()
132+
# env:
133+
# LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT_BETA }}
134+
# run: |
135+
# echo "Deleting function: $FUNCTION_NAME"
136+
# aws lambda delete-function \
137+
# --function-name "$FUNCTION_NAME" \
138+
# --endpoint-url "$LAMBDA_ENDPOINT" \
139+
# --region "${{ env.AWS_REGION }}" || echo "Function already deleted or doesn't exist"

.github/workflows/integration-tests.yml

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ jobs:
2222
with:
2323
path: language-sdk
2424

25-
- name: Parse testing SDK branch from PR body
26-
id: parse
27-
run: python language-sdk/ops/parse_sdk_branch.py
28-
env:
29-
PR_BODY: ${{ github.event.pull_request.body }}
30-
31-
- name: Checkout Testing SDK
32-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
33-
with:
34-
repository: aws/aws-durable-execution-sdk-python-testing
35-
ref: ${{ steps.parse.outputs.testing_ref }}
36-
path: testing-sdk
37-
3825
- name: Set up Python ${{ matrix.python-version }}
3926
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
4027
with:
@@ -44,12 +31,9 @@ jobs:
4431
run: python -m pip install hatch==1.16.5
4532

4633
- name: Setup and run Testing SDK
47-
working-directory: testing-sdk
48-
env:
49-
AWS_DURABLE_SDK_URL: file://${{ github.workspace }}/language-sdk
34+
working-directory: language-sdk
5035
run: |
51-
echo "Running Testing SDK tests against Language SDK PR changes..."
52-
echo "Using Language SDK from: $AWS_DURABLE_SDK_URL"
36+
echo "Running SDK tests against Language SDK PR changes..."
5337
hatch run -- test:pip install -e ../language-sdk
5438
hatch fmt --check
5539
hatch run types:check
@@ -70,19 +54,6 @@ jobs:
7054
with:
7155
path: language-sdk
7256

73-
- name: Parse testing SDK branch from PR body
74-
id: parse
75-
run: python language-sdk/ops/parse_sdk_branch.py
76-
env:
77-
PR_BODY: ${{ github.event.pull_request.body }}
78-
79-
- name: Checkout Testing SDK
80-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
81-
with:
82-
repository: aws/aws-durable-execution-sdk-python-testing
83-
ref: ${{ steps.parse.outputs.testing_ref }}
84-
path: testing-sdk
85-
8657
- name: Set up Python 3.13
8758
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
8859
with:
@@ -95,17 +66,9 @@ jobs:
9566
role-session-name: languageSDKIntegrationTest
9667
aws-region: ${{ env.AWS_REGION }}
9768

98-
- name: Install Hatch and setup Testing SDK
99-
working-directory: testing-sdk
100-
env:
101-
AWS_DURABLE_SDK_URL: file://${{ github.workspace }}/language-sdk
102-
run: |
103-
pip install hatch==1.16.5
104-
python -m pip install -e .
105-
10669
- name: Get integration examples
10770
id: get-examples
108-
working-directory: testing-sdk/examples
71+
working-directory: language-sdk/examples
10972
run: |
11073
echo "examples=$(jq -c '.examples | map(select(.integration == true)) | .[0:2]' examples-catalog.json)" >> $GITHUB_OUTPUT
11174
@@ -116,10 +79,10 @@ jobs:
11679
rm /tmp/awscliv2.zip
11780
sudo /tmp/aws/install --update
11881
rm -rf /tmp/aws/
82+
11983
- name: Deploy and test examples
120-
working-directory: testing-sdk
84+
working-directory: language-sdk
12185
env:
122-
AWS_DURABLE_SDK_URL: file://${{ github.workspace }}/language-sdk
12386
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
12487
LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }}
12588
INVOKE_ACCOUNT_ID: ${{ secrets.INVOKE_ACCOUNT_ID }}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Update SAM Template
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "examples/**"
7+
8+
permissions:
9+
contents: write
10+
11+
concurrency:
12+
group: ${{ github.head_ref }}-${{ github.run_id}}-sam-template
13+
cancel-in-progress: true
14+
15+
jobs:
16+
update-template:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
ref: ${{ github.head_ref }}
23+
24+
- name: Set up Python 3.13
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.13"
28+
29+
- name: Generate SAM template
30+
run: python examples/scripts/generate_sam_template.py
31+
32+
- name: Commit and push changes
33+
run: |
34+
git config --local user.email "action@github.com"
35+
git config --local user.name "GitHub Action"
36+
git add .
37+
if git diff --staged --quiet; then
38+
echo "No changes to commit"
39+
else
40+
git commit -m "chore: update SAM template" --no-verify
41+
git push
42+
fi

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ dist/
2828

2929
.idea
3030

31-
.kiro/
31+
.kiro/
32+
33+
/examples/build/*
34+
/examples/*.zip

CONTRIBUTING.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,47 @@ Mimic the package structure in the src/aws_durable_execution_sdk_python director
203203
Name your module so that src/mypackage/mymodule.py has a dedicated unit test file
204204
tests/mypackage/mymodule_test.py
205205

206+
## Examples and Deployment
207+
208+
The project includes a unified CLI tool for managing examples, deployment, and AWS account setup:
209+
210+
### Bootstrap AWS Account
211+
```bash
212+
# Set up IAM role and KMS key for durable functions
213+
export AWS_ACCOUNT_ID=your-account-id
214+
hatch run examples:bootstrap
215+
```
216+
217+
### Build and Deploy Examples
218+
```bash
219+
# Build all examples with dependencies
220+
hatch run examples:build
221+
222+
# Generate SAM template for all examples
223+
hatch run examples:generate-sam-template
224+
225+
# List available examples
226+
hatch run examples:list
227+
228+
# Deploy specific example (when durable functions are available)
229+
hatch run examples:deploy "Hello World"
230+
```
231+
232+
### Other CLI Commands
233+
```bash
234+
# Invoke deployed function
235+
hatch run examples:invoke function-name --payload '{}'
236+
237+
# Get execution details
238+
hatch run examples:get execution-arn
239+
240+
# Get execution history
241+
hatch run examples:history execution-arn
242+
243+
# Clean build artifacts
244+
hatch run examples:clean
245+
```
246+
206247
## Coverage
207248
```
208249
hatch run test:cov

0 commit comments

Comments
 (0)