From b1f62bb7117d4aa070000e62affc03dbbca4ba98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Thu, 22 Oct 2026 11:38:52 -0400 Subject: [PATCH] fix(aws-lambda): smoke the arm64 image through its own Lambda runtime The smoke is now a handler invoked through the image's entrypoint, whose bootstrap sets AWS_EXECUTION_ENV the way Lambda does, so @sparticuz/chromium takes its Lambda branch with nothing set by hand. It returns the value it saw. --- .github/workflows/lambda-arm64-image.yml | 17 +++++---- packages/aws-lambda/image/smoke-video.mjs | 44 +++++++++++++---------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/.github/workflows/lambda-arm64-image.yml b/.github/workflows/lambda-arm64-image.yml index f66129a21c..1f330694b2 100644 --- a/.github/workflows/lambda-arm64-image.yml +++ b/.github/workflows/lambda-arm64-image.yml @@ -86,15 +86,20 @@ jobs: run: >- docker buildx build --progress=plain --platform linux/arm64 --target video --build-context task=staged/task --load -t hf-video:ci packages/aws-lambda/image - - name: ffmpeg and Chrome run in the image - run: >- - docker run --rm --entrypoint /var/lang/bin/node -e AWS_EXECUTION_ENV=AWS_Lambda_nodejs22.x - -v "$PWD/packages/aws-lambda/image/smoke-video.mjs:/var/task/smoke-video.mjs:ro" - hf-video:ci /var/task/smoke-video.mjs + - name: ffmpeg and Chrome run under the image's own Lambda runtime + run: | + docker run -d --name hf-smoke -p 9001:8080 \ + -v "$PWD/packages/aws-lambda/image/smoke-video.mjs:/var/task/smoke-video.mjs:ro" \ + hf-video:ci smoke-video.handler + reply=$(curl -sS --retry 30 --retry-all-errors --retry-delay 1 \ + -d '{}' http://localhost:9001/2015-03-31/functions/function/invocations) + docker logs hf-smoke + echo "$reply" + jq -e '.arch == "arm64" and .screenshotBytes > 0 and (.ffmpeg | startswith("ffmpeg version 7.0.2"))' <<<"$reply" - name: The Lambda runtime loads the handler run: | docker run -d --name hf-video -p 9000:8080 hf-video:ci - reply=$(curl -sS --retry 20 --retry-connrefused --retry-delay 1 \ + reply=$(curl -sS --retry 30 --retry-all-errors --retry-delay 1 \ -d '{"Action":"not-an-action"}' http://localhost:9000/2015-03-31/functions/function/invocations) docker logs hf-video echo "$reply" diff --git a/packages/aws-lambda/image/smoke-video.mjs b/packages/aws-lambda/image/smoke-video.mjs index 6f4337efcf..94b61d0027 100644 --- a/packages/aws-lambda/image/smoke-video.mjs +++ b/packages/aws-lambda/image/smoke-video.mjs @@ -1,22 +1,30 @@ -// Runs inside the video image, mounted into /var/task: the bundled ffmpeg answers and the arm64 Chrome -// renders a page, launched the way src/chromium.ts launches it. +// A handler mounted into the video image and invoked through its own Lambda bootstrap, which sets +// AWS_EXECUTION_ENV as Lambda does: the bundled ffmpeg answers and arm64 Chrome renders, launched as +// src/chromium.ts launches it. import { execFileSync } from "node:child_process"; import chromium from "@sparticuz/chromium"; import puppeteer from "puppeteer-core"; -const ffmpeg = execFileSync("/var/task/bin/ffmpeg", ["-hide_banner", "-version"], { - encoding: "utf-8", -}); -console.log(ffmpeg.split("\n")[0]); -const browser = await puppeteer.launch({ - executablePath: await chromium.executablePath(), - args: chromium.args, -}); -try { - const page = await browser.newPage(); - await page.setContent("
"); - const shot = await page.screenshot({ clip: { x: 0, y: 0, width: 64, height: 64 } }); - console.log(`${await browser.version()} on ${process.arch}: ${shot.length} byte screenshot`); -} finally { - await browser.close(); -} +export const handler = async () => { + const ffmpeg = execFileSync("/var/task/bin/ffmpeg", ["-hide_banner", "-version"], { + encoding: "utf-8", + }).split("\n")[0]; + const browser = await puppeteer.launch({ + executablePath: await chromium.executablePath(), + args: chromium.args, + }); + try { + const page = await browser.newPage(); + await page.setContent("
"); + const shot = await page.screenshot({ clip: { x: 0, y: 0, width: 64, height: 64 } }); + return { + executionEnv: process.env.AWS_EXECUTION_ENV, + arch: process.arch, + ffmpeg, + chrome: await browser.version(), + screenshotBytes: shot.length, + }; + } finally { + await browser.close(); + } +};