diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 16dca1c..af9adb4 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -40,8 +40,10 @@ jobs: include: - arch: arm64 project: project-aws-aws-lambda-nodejs-runtime-arm64 + lambda_arch: arm64 - arch: amd64 project: project-aws-aws-lambda-nodejs-runtime-x86 + lambda_arch: x86_64 runs-on: - codebuild-${{ matrix.project }}-${{ github.run_id }}-${{ github.run_attempt }} - instance-size:2xlarge @@ -55,6 +57,8 @@ jobs: BUILDKIT_PROGRESS: plain ARCH: ${{ matrix.arch }} IMAGE: lambda-runtime/image:nodejs26.x-mainline-${{ matrix.arch }} + FUNCTION_NAME: nodejs-runtime-integ-${{ matrix.arch }} + IMAGE_TAG: integ-${{ matrix.arch }}-${{ github.run_id }}-${{ github.run_attempt }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -113,7 +117,76 @@ jobs: - name: Security-test the image run: node test/run.mjs "$IMAGE" "linux/$ARCH" test/security-cases.json - - name: Configure AWS credentials (OIDC) + - name: Configure AWS credentials (integration test) + if: github.event_name == 'push' + uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0 + with: + role-to-assume: ${{ secrets.AWS_INTEGRATION_ROLE_ARN }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Log in to Amazon ECR (integration test) + if: github.event_name == 'push' + id: login-ecr-integ + uses: aws-actions/amazon-ecr-login@7290e214a610b32bc0eef81748948b6d466a8783 # v2.2.0 + + - name: Build and push the hello-world test image + if: github.event_name == 'push' + id: integ-build + env: + ECR_REGISTRY: ${{ steps.login-ecr-integ.outputs.registry }} + INTEG_ECR_REPOSITORY: ${{ secrets.INTEG_ECR_REPOSITORY }} + run: | + set -euo pipefail + image="${ECR_REGISTRY}/${INTEG_ECR_REPOSITORY}:${IMAGE_TAG}" + # Layer the hello-world handler onto the image just built locally. Single-platform and + # no attestations: Lambda needs a Docker media-type manifest, not an OCI image index. + docker buildx build \ + --platform "linux/${ARCH}" \ + --provenance=false --sbom=false \ + --build-arg "RUNTIME_IMAGE=${IMAGE}" \ + --tag "$image" \ + --push \ + test/integration + echo "image_uri=${image}" >> "$GITHUB_OUTPUT" + + - name: Deploy the test Lambda function + if: github.event_name == 'push' + uses: aws-actions/aws-lambda-deploy@d496277188b89f0be02d7a2216fc912c0427702a # v1.1.2 + with: + function-name: ${{ env.FUNCTION_NAME }} + package-type: Image + image-uri: ${{ steps.integ-build.outputs.image_uri }} + role: ${{ secrets.AWS_LAMBDA_EXEC_ROLE_ARN }} + architectures: ${{ matrix.lambda_arch }} + memory-size: 256 + timeout: 30 + + - name: Invoke the test function and assert 200 + if: github.event_name == 'push' + working-directory: test/integration + run: | + set -euo pipefail + if [ -n "${NPMRC:-}" ]; then + npm install --userconfig "$NPMRC" + else + npm install + fi + node invoke.mjs "$FUNCTION_NAME" + + - name: Destroy the test Lambda function + if: always() && github.event_name == 'push' + run: aws lambda delete-function --function-name "$FUNCTION_NAME" || true + + - name: Delete the pushed test image + if: always() && github.event_name == 'push' + env: + INTEG_ECR_REPOSITORY: ${{ secrets.INTEG_ECR_REPOSITORY }} + run: | + aws ecr batch-delete-image \ + --repository-name "$INTEG_ECR_REPOSITORY" \ + --image-ids imageTag="$IMAGE_TAG" || true + + - name: Configure AWS credentials (source push) if: github.event_name == 'push' uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0 with: @@ -123,7 +196,7 @@ jobs: - name: Log in to Amazon ECR if: github.event_name == 'push' id: login-ecr - uses: aws-actions/amazon-ecr-login@03f1aad4c6c7ffd436567f42f9384779290529bd # v2.1.7 + uses: aws-actions/amazon-ecr-login@7290e214a610b32bc0eef81748948b6d466a8783 # v2.2.0 - name: Push the image if: github.event_name == 'push' diff --git a/test/integration/Dockerfile b/test/integration/Dockerfile new file mode 100644 index 0000000..69cc796 --- /dev/null +++ b/test/integration/Dockerfile @@ -0,0 +1,4 @@ +ARG RUNTIME_IMAGE +FROM ${RUNTIME_IMAGE} +COPY app.js /var/task/ +CMD ["app.handler"] diff --git a/test/integration/app.js b/test/integration/app.js new file mode 100644 index 0000000..cca7180 --- /dev/null +++ b/test/integration/app.js @@ -0,0 +1,7 @@ +exports.handler = async (event) => { + console.log("integration-test handler invoked:", JSON.stringify(event)); + return { + statusCode: 200, + body: JSON.stringify({ message: "hello world", node: process.version }), + }; +}; diff --git a/test/integration/invoke.mjs b/test/integration/invoke.mjs new file mode 100644 index 0000000..2a2903e --- /dev/null +++ b/test/integration/invoke.mjs @@ -0,0 +1,55 @@ +import { + LambdaClient, + InvokeCommand, + waitUntilFunctionActiveV2, +} from "@aws-sdk/client-lambda"; + +const functionName = process.argv[2]; +if (!functionName) { + console.error("usage: node invoke.mjs FUNCTION_NAME"); + process.exit(2); +} + +const client = new LambdaClient({}); + +console.log(`waiting for ${functionName} to become Active...`); +await waitUntilFunctionActiveV2({ client, maxWaitTime: 300 }, { FunctionName: functionName }); + +console.log(`invoking ${functionName}...`); +const response = await client.send( + new InvokeCommand({ + FunctionName: functionName, + Payload: Buffer.from(JSON.stringify({ source: "integration-test" })), + }), +); + +const payloadText = response.Payload ? Buffer.from(response.Payload).toString("utf8") : ""; +console.log(`StatusCode: ${response.StatusCode}`); +console.log(`FunctionError: ${response.FunctionError ?? "(none)"}`); +console.log(`Payload: ${payloadText}`); + +const failures = []; +if (response.StatusCode !== 200) { + failures.push(`expected Invoke StatusCode 200, got ${response.StatusCode}`); +} +if (response.FunctionError) { + failures.push(`function reported an error: ${response.FunctionError}`); +} + +let payload; +try { + payload = JSON.parse(payloadText); +} catch { + failures.push(`response payload was not JSON: ${payloadText}`); +} +if (payload && payload.statusCode !== 200) { + failures.push(`expected handler payload statusCode 200, got ${JSON.stringify(payload.statusCode)}`); +} + +if (failures.length) { + console.error("FAIL"); + for (const failure of failures) console.error(` - ${failure}`); + process.exit(1); +} + +console.log("PASS: invocation returned 200"); diff --git a/test/integration/package.json b/test/integration/package.json new file mode 100644 index 0000000..7a26dff --- /dev/null +++ b/test/integration/package.json @@ -0,0 +1,10 @@ +{ + "name": "nodejs-runtime-integration-test", + "version": "1.0.0", + "private": true, + "type": "module", + "description": "SDK invoke client for the runtime image integration test", + "dependencies": { + "@aws-sdk/client-lambda": "^3.0.0" + } +}