Skip to content

Commit 003729a

Browse files
committed
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.
1 parent 04eef55 commit 003729a

2 files changed

Lines changed: 37 additions & 24 deletions

File tree

‎.github/workflows/lambda-arm64-image.yml‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,20 @@ jobs:
8686
run: >-
8787
docker buildx build --progress=plain --platform linux/arm64 --target video
8888
--build-context task=staged/task --load -t hf-video:ci packages/aws-lambda/image
89-
- name: ffmpeg and Chrome run in the image
90-
run: >-
91-
docker run --rm --entrypoint /var/lang/bin/node -e AWS_EXECUTION_ENV=AWS_Lambda_nodejs22.x
92-
-v "$PWD/packages/aws-lambda/image/smoke-video.mjs:/var/task/smoke-video.mjs:ro"
93-
hf-video:ci /var/task/smoke-video.mjs
89+
- name: ffmpeg and Chrome run under the image's own Lambda runtime
90+
run: |
91+
docker run -d --name hf-smoke -p 9001:8080 \
92+
-v "$PWD/packages/aws-lambda/image/smoke-video.mjs:/var/task/smoke-video.mjs:ro" \
93+
hf-video:ci smoke-video.handler
94+
reply=$(curl -sS --retry 30 --retry-all-errors --retry-delay 1 \
95+
-d '{}' http://localhost:9001/2015-03-31/functions/function/invocations)
96+
docker logs hf-smoke
97+
echo "$reply"
98+
jq -e '.arch == "arm64" and .screenshotBytes > 0 and (.ffmpeg | startswith("ffmpeg version 7.0.2"))' <<<"$reply"
9499
- name: The Lambda runtime loads the handler
95100
run: |
96101
docker run -d --name hf-video -p 9000:8080 hf-video:ci
97-
reply=$(curl -sS --retry 20 --retry-connrefused --retry-delay 1 \
102+
reply=$(curl -sS --retry 30 --retry-all-errors --retry-delay 1 \
98103
-d '{"Action":"not-an-action"}' http://localhost:9000/2015-03-31/functions/function/invocations)
99104
docker logs hf-video
100105
echo "$reply"
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
// Runs inside the video image, mounted into /var/task: the bundled ffmpeg answers and the arm64 Chrome
2-
// renders a page, launched the way src/chromium.ts launches it.
1+
// A handler mounted into the video image and invoked through its own Lambda bootstrap, which sets
2+
// AWS_EXECUTION_ENV as Lambda does: the bundled ffmpeg answers and arm64 Chrome renders, launched as
3+
// src/chromium.ts launches it.
34
import { execFileSync } from "node:child_process";
45
import chromium from "@sparticuz/chromium";
56
import puppeteer from "puppeteer-core";
67

7-
const ffmpeg = execFileSync("/var/task/bin/ffmpeg", ["-hide_banner", "-version"], {
8-
encoding: "utf-8",
9-
});
10-
console.log(ffmpeg.split("\n")[0]);
11-
const browser = await puppeteer.launch({
12-
executablePath: await chromium.executablePath(),
13-
args: chromium.args,
14-
});
15-
try {
16-
const page = await browser.newPage();
17-
await page.setContent("<div style='width:64px;height:64px;background:#0a0'></div>");
18-
const shot = await page.screenshot({ clip: { x: 0, y: 0, width: 64, height: 64 } });
19-
console.log(`${await browser.version()} on ${process.arch}: ${shot.length} byte screenshot`);
20-
} finally {
21-
await browser.close();
22-
}
8+
export const handler = async () => {
9+
const ffmpeg = execFileSync("/var/task/bin/ffmpeg", ["-hide_banner", "-version"], {
10+
encoding: "utf-8",
11+
}).split("\n")[0];
12+
const browser = await puppeteer.launch({
13+
executablePath: await chromium.executablePath(),
14+
args: chromium.args,
15+
});
16+
try {
17+
const page = await browser.newPage();
18+
await page.setContent("<div style='width:64px;height:64px;background:#0a0'></div>");
19+
const shot = await page.screenshot({ clip: { x: 0, y: 0, width: 64, height: 64 } });
20+
return {
21+
executionEnv: process.env.AWS_EXECUTION_ENV,
22+
arch: process.arch,
23+
ffmpeg,
24+
chrome: await browser.version(),
25+
screenshotBytes: shot.length,
26+
};
27+
} finally {
28+
await browser.close();
29+
}
30+
};

0 commit comments

Comments
 (0)