-
Notifications
You must be signed in to change notification settings - Fork 20
134 lines (115 loc) · 3.71 KB
/
lambda-nodejs-integ-tests.yml
File metadata and controls
134 lines (115 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: CDK Lambda DSQL Sample Test
permissions: {}
on:
push:
branches: [ main ]
paths:
- 'lambda/**'
- '.github/workflows/lambda-nodejs-integ-tests.yml'
pull_request:
branches: [ main ]
paths:
- 'lambda/**'
- '.github/workflows/lambda-nodejs-integ-tests.yml'
# Give us a button to allow running the workflow on demand for testing.
workflow_dispatch:
inputs:
tags:
description: 'Manual Workflow Run'
required: false
type: string
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
id-token: write # required by aws-actions/configure-aws-credentials
concurrency:
# Ensure only 1 job uses the workflow cluster at a time.
group: ${{ github.workflow }}
defaults:
run:
working-directory: ./lambda
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'npm'
cache-dependency-path: |
./lambda/package-lock.json
./lambda/sample/package-lock.json
- name: Install dependencies
run: |
npm ci
npm --prefix ./sample ci
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.LAMBDA_IAM_ROLE }}
aws-region: us-east-1
- name: CDK Deploy
run: |
npx cdk deploy --require-approval never --quiet --no-lookups 2>&1 | sed -E 's/[0-9]{12}/XXXXXXXXXXXX/g'
integration-test:
needs: build-and-deploy
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./lambda
permissions:
id-token: write # required by aws-actions/configure-aws-credentials
concurrency:
# Ensure only 1 job uses the workflow cluster at a time.
group: ${{ github.workflow }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'npm'
cache-dependency-path: |
./lambda/package-lock.json
./lambda/sample/package-lock.json
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.LAMBDA_IAM_ROLE }}
aws-region: us-east-1
- name: Update AWS CLI to latest version
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
sudo ./aws/install --update
aws --version
- name: Run sample Lambda
run: |
RESPONSE=$(aws lambda invoke \
--function-name DsqlLambdaSample \
--query 'FunctionError' \
--output text \
response.json)
if [ "$RESPONSE" != "None" ] && [ -n "$RESPONSE" ]; then
echo "Lambda invocation failed with error: $RESPONSE"
exit 1
fi
if [ -f response.json ] && jq -e '.endpoint' response.json > /dev/null; then
echo "Lambda execution successful"
else
if [ -f response.json ]; then
echo "Response content:"
cat response.json
else
echo "Response file not found"
fi
exit 1
fi
- name: Clean up CDK deployment
if: always() # Run even if previous steps failed
run: |
echo "Cleaning up CDK deployment"
npm ci
npx cdk destroy --force --require-approval never --no-lookups 2>&1 | sed -E 's/[0-9]{12}/XXXXXXXXXXXX/g'