diff --git a/.github/workflows/lambda-nodejs-integ-tests.yml b/.github/workflows/lambda-nodejs-integ-tests.yml new file mode 100644 index 00000000..0e3a4fae --- /dev/null +++ b/.github/workflows/lambda-nodejs-integ-tests.yml @@ -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' diff --git a/lambda/cdk.js b/lambda/cdk.js index 366ee7a9..06410ab8 100644 --- a/lambda/cdk.js +++ b/lambda/cdk.js @@ -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'), diff --git a/lambda/package.json b/lambda/package.json index dcd46bf4..9b8b86e2 100644 --- a/lambda/package.json +++ b/lambda/package.json @@ -7,7 +7,6 @@ "cdk": "cdk" }, "dependencies": { - "aws-cdk-lib": "^2.200.1", - "path": "^0.12.7" + "aws-cdk-lib": "^2.200.1" } }