|
| 1 | +name: Deploy Python Examples |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [ "main", "development"] |
| 6 | + paths: |
| 7 | + - 'src/aws_durable_execution_sdk_python_testing/**' |
| 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@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 custom Lambda model |
| 64 | + run: | |
| 65 | + aws configure add-model --service-model file://.github/model/lambda.json --service-name lambda |
| 66 | +
|
| 67 | + - name: Install Hatch |
| 68 | + run: pip install hatch |
| 69 | + |
| 70 | + - name: Build examples |
| 71 | + run: hatch run examples:build |
| 72 | + |
| 73 | + - name: Deploy Lambda function - ${{ matrix.example.name }} |
| 74 | + env: |
| 75 | + AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} |
| 76 | + LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }} |
| 77 | + INVOKE_ACCOUNT_ID: ${{ secrets.INVOKE_ACCOUNT_ID }} |
| 78 | + KMS_KEY_ARN: ${{ secrets.KMS_KEY_ARN }} |
| 79 | + run: | |
| 80 | + # Build function name |
| 81 | + EXAMPLE_NAME_CLEAN=$(echo "${{ matrix.example.name }}" | sed 's/ //g') |
| 82 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 83 | + FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-Python-PR-${{ github.event.number }}" |
| 84 | + else |
| 85 | + FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-Python" |
| 86 | + fi |
| 87 | + |
| 88 | + # Extract handler file name |
| 89 | + HANDLER_FILE=$(echo "${{ matrix.example.handler }}" | sed 's/\.handler$//') |
| 90 | + |
| 91 | + echo "Deploying $HANDLER_FILE as $FUNCTION_NAME" |
| 92 | + hatch run examples:deploy "$HANDLER_FILE" "$FUNCTION_NAME" |
| 93 | + |
| 94 | + # Store function name for later steps |
| 95 | + echo "FUNCTION_NAME=$FUNCTION_NAME" >> $GITHUB_ENV |
| 96 | +
|
| 97 | + - name: Invoke Lambda function - ${{ matrix.example.name }} |
| 98 | + env: |
| 99 | + LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }} |
| 100 | + run: | |
| 101 | + echo "Testing function: $FUNCTION_NAME" |
| 102 | + aws lambda invoke \ |
| 103 | + --function-name "$FUNCTION_NAME" \ |
| 104 | + --cli-binary-format raw-in-base64-out \ |
| 105 | + --payload '{"name": "World"}' \ |
| 106 | + --region "${{ env.AWS_REGION }}" \ |
| 107 | + --endpoint-url "$LAMBDA_ENDPOINT" \ |
| 108 | + /tmp/response.json \ |
| 109 | + > /tmp/invoke_response.json |
| 110 | + |
| 111 | + echo "Response:" |
| 112 | + cat /tmp/response.json |
| 113 | + |
| 114 | + echo "Full Invoke Response:" |
| 115 | + cat /tmp/invoke_response.json |
| 116 | + |
| 117 | + echo "All Response Headers:" |
| 118 | + jq -r '.ResponseMetadata.HTTPHeaders' /tmp/invoke_response.json || echo "No HTTPHeaders found" |
| 119 | + |
| 120 | + # Extract invocation ID from response headers |
| 121 | + INVOCATION_ID=$(jq -r '.ResponseMetadata.HTTPHeaders["x-amzn-invocation-id"] // empty' /tmp/invoke_response.json) |
| 122 | + if [ -n "$INVOCATION_ID" ]; then |
| 123 | + echo "INVOCATION_ID=$INVOCATION_ID" >> $GITHUB_ENV |
| 124 | + echo "Captured Invocation ID: $INVOCATION_ID" |
| 125 | + else |
| 126 | + echo "Warning: Could not capture invocation ID from response" |
| 127 | + fi |
| 128 | +
|
| 129 | + - name: Find Durable Execution - ${{ matrix.example.name }} |
| 130 | + env: |
| 131 | + LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }} |
| 132 | + run: | |
| 133 | + echo "Listing durable executions for function: $FUNCTION_NAME" |
| 134 | + aws lambda list-durable-executions \ |
| 135 | + --function-name "$FUNCTION_NAME" \ |
| 136 | + --region "${{ env.AWS_REGION }}" \ |
| 137 | + --endpoint-url "$LAMBDA_ENDPOINT" \ |
| 138 | + --cli-binary-format raw-in-base64-out \ |
| 139 | + --status-filter SUCCEEDED \ |
| 140 | + > /tmp/executions.json |
| 141 | + echo "Durable Executions:" |
| 142 | + cat /tmp/executions.json |
| 143 | + |
| 144 | + # Extract the first execution ARN for history retrieval |
| 145 | + EXECUTION_ARN=$(jq -r '.DurableExecutions[0].DurableExecutionArn // empty' /tmp/executions.json) |
| 146 | + echo "EXECUTION_ARN=$EXECUTION_ARN" >> $GITHUB_ENV |
| 147 | +
|
| 148 | + - name: Get Durable Execution History - ${{ matrix.example.name }} |
| 149 | + if: env.EXECUTION_ARN != '' |
| 150 | + env: |
| 151 | + LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }} |
| 152 | + run: | |
| 153 | + echo "Getting execution history for: $EXECUTION_ARN" |
| 154 | + aws lambda get-durable-execution-history \ |
| 155 | + --durable-execution-arn "$EXECUTION_ARN" \ |
| 156 | + --region "${{ env.AWS_REGION }}" \ |
| 157 | + --endpoint-url "$LAMBDA_ENDPOINT" \ |
| 158 | + --cli-binary-format raw-in-base64-out \ |
| 159 | + > /tmp/history.json |
| 160 | + echo "Execution History:" |
| 161 | + cat /tmp/history.json |
| 162 | +
|
| 163 | + # - name: Cleanup Lambda function |
| 164 | + # if: always() |
| 165 | + # env: |
| 166 | + # LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }} |
| 167 | + # run: | |
| 168 | + # echo "Deleting function: $FUNCTION_NAME" |
| 169 | + # aws lambda delete-function \ |
| 170 | + # --function-name "$FUNCTION_NAME" \ |
| 171 | + # --endpoint-url "$LAMBDA_ENDPOINT" \ |
| 172 | + # --region "${{ env.AWS_REGION }}" || echo "Function already deleted or doesn't exist" |
0 commit comments