Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions .github/workflows/lambda-nodejs-integ-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: CDK Lambda DSQL Sample Test

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
contents: read
actions: read
checks: write
pull-requests: write
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 install
npm --prefix ./sample install

- 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
contents: read

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 install
npx cdk destroy --force --require-approval never --no-lookups 2>&1 | sed -E 's/[0-9]{12}/XXXXXXXXXXXX/g'
3 changes: 2 additions & 1 deletion lambda/cdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class DsqlLambdaStack extends Stack {
});

// Define the Lambda function
const dsqlFunction = new Function(this, 'DsqlSample', {
const dsqlFunction = new Function(this, 'DsqlLambdaSample', {
functionName: 'DsqlLambdaSample',
runtime: Runtime.NODEJS_22_X,
handler: 'lambda.handler',
code: Code.fromAsset('sample'),
Expand Down
3 changes: 1 addition & 2 deletions lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"cdk": "cdk"
},
"dependencies": {
"aws-cdk-lib": "^2.200.1",
"path": "^0.12.7"
"aws-cdk-lib": "^2.200.1"
}
}
Loading