Skip to content

Commit 81d73d2

Browse files
jrusso1020claude
andauthored
fix(aws-lambda): chrome-headless-shell 158 in the arm64 video image, sparticuz 153 in the x86 ZIP (#8155)
* fix(aws-lambda): run chrome-headless-shell 158 in the arm64 video image The arm64 video image now installs Chrome for Testing's linux-arm64 chrome-headless-shell 158.0.8127.36, pinned by sha256 and fetched with curl -f, as the whole shell folder. The Lambda Node 22 base has none of the shared libraries the shell links and no fonts, so the image installs them from the base's repository at the same pinned release. The image sets HYPERFRAMES_LAMBDA_CHROME_SOURCE and HYPERFRAMES_LAMBDA_CHROME_PATH itself, and the nested video function no longer passes ChromeSource, which would override them. stage-arm64-image.ts stops fetching the sparticuz arm64 pack and drops the ZIP's x86 sparticuz Chrome instead. The x86 handler ZIP stays on @sparticuz/chromium, bumped from 148.0.0 to 153.0.0. It builds at 258,502,222 bytes unzipped, under Lambda's 262,144,000-byte limit and the 248 MiB in-house gate. Two fixes for --source=chrome-headless-shell: - build-zip.ts staged only the executable, which exits at launch without its ICU data and .pak files. It now stages the whole shell folder at chrome-headless-shell-linux64/. - Nothing set HYPERFRAMES_LAMBDA_CHROME_PATH, which src/chromium.ts requires for that source. The SAM template and the CDK stack now set it to the bundled shell when ChromeSource asks for it. Drops the unused @types/aws-lambda devDependency, which the dead-code audit reports whenever this package's manifest changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci(publish): build the Lambda arm64 video image on an ARM runner The video stage now installs Chrome's system libraries with microdnf, so it runs code for arm64. The pack job built that image on ubuntu-latest with no emulation, which it could do only while the stage copied files. A new lambda-video-image job builds it natively on ubuntu-24.04-arm, from the handler zip whose sha256 the zip job reported, and reports the OCI tarball's sha256. Pack downloads that tarball, checks the sha256 against the job's, and pins it as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(aws-lambda): fit the comment ratchet and the package size budget chromium.ts loses the two doc lines on BUNDLED_SHELL_DIR and BUNDLED_SHELL_PATH; the names and the SAM template's comment already say what they are. @hyperframes/aws-lambda's unpacked budget goes from 290,508 to 298,000 bytes. The package unpacks to 295,324 bytes, up from the shared chrome-headless-shell staging module the ZIP and image scripts now import and from the README and docs that describe the two Chrome sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3b79b18 commit 81d73d2

27 files changed

Lines changed: 394 additions & 202 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- "packages/aws-lambda/image/**"
1212
- "packages/aws-lambda/hf-media-linux-aarch64.sha256"
1313
- "packages/aws-lambda/scripts/stage-arm64-image.ts"
14-
# A @sparticuz/chromium bump or a ZIP layout change must re-stage the image.
14+
# A dependency bump or a ZIP layout change must re-stage the image.
1515
- "packages/aws-lambda/package.json"
1616
- "packages/aws-lambda/scripts/build-zip.ts"
1717
- "packages/aws-lambda/scripts/runtimeLock.ts"

‎.github/workflows/publish.yml‎

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,73 @@ jobs:
265265
path: packages/aws-lambda/dist/handler.zip
266266
if-no-files-found: error
267267

268+
# The video stage installs Chrome's system libraries with microdnf, so it builds on ARM, not under emulation.
269+
lambda-video-image:
270+
name: Lambda video image
271+
needs: [release-source, lambda-arm64-ffmpeg, lambda-handler-zip]
272+
runs-on: ubuntu-24.04-arm
273+
timeout-minutes: 30
274+
permissions:
275+
contents: read
276+
env:
277+
EXPECTED_RELEASE_SHA: ${{ needs.release-source.outputs.sha }}
278+
if: needs.release-source.outputs.sha != ''
279+
outputs:
280+
sha256: ${{ steps.image.outputs.sha256 }}
281+
steps:
282+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
283+
with:
284+
ref: ${{ env.EXPECTED_RELEASE_SHA }}
285+
persist-credentials: false
286+
- name: Verify immutable release checkout
287+
run: |
288+
ACTUAL_SHA="$(git rev-parse HEAD)"
289+
EXPECTED_COMMIT_SHA="$(git rev-parse "${EXPECTED_RELEASE_SHA}^{commit}")"
290+
if [ "$ACTUAL_SHA" != "$EXPECTED_COMMIT_SHA" ]; then
291+
echo "::error::Expected release commit $EXPECTED_COMMIT_SHA, checked out $ACTUAL_SHA"
292+
exit 1
293+
fi
294+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
295+
with:
296+
no-cache: true
297+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
298+
with:
299+
name: hyperframes-lambda-handler-zip
300+
path: dist/lambda-handler-build
301+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
302+
with:
303+
name: hf-media-linux-aarch64
304+
path: dist/hf-media
305+
- name: Build Lambda video image
306+
id: image
307+
env:
308+
EXPECTED_ZIP_SHA256: ${{ needs.lambda-handler-zip.outputs.sha256 }}
309+
run: |
310+
ACTUAL_ZIP_SHA256="$(sha256sum dist/lambda-handler-build/handler.zip | cut -d' ' -f1)"
311+
if [ -z "$EXPECTED_ZIP_SHA256" ] || [ "$ACTUAL_ZIP_SHA256" != "$EXPECTED_ZIP_SHA256" ]; then
312+
echo "::error::Lambda handler zip sha256 $ACTUAL_ZIP_SHA256 does not match the build job's $EXPECTED_ZIP_SHA256"
313+
exit 1
314+
fi
315+
bun packages/aws-lambda/scripts/stage-arm64-image.ts --zip=dist/lambda-handler-build/handler.zip \
316+
--ffmpeg=dist/hf-media/hf-media-linux-aarch64.tar.gz --out=dist/arm64-image
317+
# OCI export needs a docker-container builder; no attestations, so index.json lists one image.
318+
docker buildx create --use
319+
docker buildx build --progress=plain --platform linux/arm64 --target video \
320+
--provenance=false --sbom=false --build-context task=dist/arm64-image/task \
321+
--output type=oci,dest=dist/hyperframes-lambda-video-arm64.oci.tar packages/aws-lambda/image
322+
echo "sha256=$(sha256sum dist/hyperframes-lambda-video-arm64.oci.tar | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
323+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
324+
with:
325+
name: hyperframes-lambda-video-arm64
326+
overwrite: true
327+
path: dist/hyperframes-lambda-video-arm64.oci.tar
328+
if-no-files-found: error
329+
268330
pack:
269331
name: Build and pack
270332
outputs:
271333
bundle_id: ${{ steps.previous_bundle.outputs.artifact || steps.bundle.outputs.artifact-id }}
272-
needs: [release-source, lambda-arm64-ffmpeg, lambda-handler-zip]
334+
needs: [release-source, lambda-handler-zip, lambda-video-image]
273335
runs-on: ubuntu-latest
274336
timeout-minutes: 30
275337
# Every build and lifecycle script of the release commit runs here, with a
@@ -385,24 +447,24 @@ jobs:
385447
rm -rf dist/lambda-handler-build
386448
bun packages/aws-lambda/scripts/pin-handler-zip.ts
387449
450+
# lambda-video-image built it on ARM from the same zip sha pinned above.
388451
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
389452
if: steps.previous_bundle.outputs.artifact == ''
390453
with:
391-
name: hf-media-linux-aarch64
392-
path: dist/hf-media
454+
name: hyperframes-lambda-video-arm64
455+
path: dist
393456

394-
# Built from the zip pinned above. The video stage only copies files, so no emulation is needed.
395-
- name: Build Lambda video image
457+
- name: Pin Lambda video image
396458
if: steps.previous_bundle.outputs.artifact == ''
397459
id: lambda_video_image
460+
env:
461+
EXPECTED_SHA256: ${{ needs.lambda-video-image.outputs.sha256 }}
398462
run: |
399-
bun packages/aws-lambda/scripts/stage-arm64-image.ts --zip=dist/hyperframes-lambda-handler.zip \
400-
--ffmpeg=dist/hf-media/hf-media-linux-aarch64.tar.gz --out=dist/arm64-image
401-
# OCI export needs a docker-container builder; no attestations, so index.json lists one image.
402-
docker buildx create --use
403-
docker buildx build --progress=plain --platform linux/arm64 --target video \
404-
--provenance=false --sbom=false --build-context task=dist/arm64-image/task \
405-
--output type=oci,dest=dist/hyperframes-lambda-video-arm64.oci.tar packages/aws-lambda/image
463+
ACTUAL_SHA256="$(sha256sum dist/hyperframes-lambda-video-arm64.oci.tar | cut -d' ' -f1)"
464+
if [ -z "$EXPECTED_SHA256" ] || [ "$ACTUAL_SHA256" != "$EXPECTED_SHA256" ]; then
465+
echo "::error::Lambda video image sha256 $ACTUAL_SHA256 does not match the build job's $EXPECTED_SHA256"
466+
exit 1
467+
fi
406468
bun packages/aws-lambda/scripts/pin-handler-zip.ts --video-image
407469
408470
- run: bun run verify:packed-manifests

‎bun.lock‎

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/deploy/aws-lambda.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The stack's bucket expires objects under `cas/sha256/` 30 days after they were l
104104

105105
#### Upgrading from a version that deployed x86 only
106106

107-
`lambda deploy` now runs the plan and the render chunks on an arm64 container-image function by default; audio and assemble stay on the x86 function. Redeploying an existing stack without `--video-arch` moves it to arm64 and adds the `<stack>-video` ECR repository. To keep a stack on x86, pass `--video-arch x86_64` on every deploy. `--chrome-source chrome-headless-shell` also needs `--video-arch x86_64`, because the arm64 image bundles sparticuz Chrome only.
107+
`lambda deploy` now runs the plan and the render chunks on an arm64 container-image function by default; audio and assemble stay on the x86 function. Redeploying an existing stack without `--video-arch` moves it to arm64 and adds the `<stack>-video` ECR repository. To keep a stack on x86, pass `--video-arch x86_64` on every deploy. `--chrome-source chrome-headless-shell` also needs `--video-arch x86_64`, because the arm64 image is built from the sparticuz handler ZIP. The arm64 image itself runs Chrome for Testing's linux-arm64 `chrome-headless-shell`, whatever `--chrome-source` says.
108108

109109
#### Upgrading from a version before shared content storage
110110

‎docs/packages/aws-lambda.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The Lambda adapter wraps the distributed producer primitives behind one dispatch
5656

5757
All three phases must fit the configured per-invocation Lambda timeout, at most 15 minutes, and the function's temporary storage. Smaller chunks can reduce each worker's extraction and rendering work, but do not divide video extraction that still happens in Plan. See [long-video planning limits](/deploy/aws-lambda#long-video-planning-times-out) for FFmpeg frame-stall timeouts and how to split jobs that cannot fit.
5858

59-
The handler uses `@sparticuz/chromium` by default, with a build-time fallback for bundling `chrome-headless-shell` directly when needed.
59+
The x86 handler ZIP uses `@sparticuz/chromium` by default, with a build-time fallback for bundling `chrome-headless-shell` directly when needed. The arm64 video image runs Chrome for Testing's linux-arm64 `chrome-headless-shell`.
6060

6161
### Page network restriction
6262

‎docs/packages/cli.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3071,7 +3071,7 @@ deploy:
30713071
| `--concurrency` | none | Lambda reserved concurrency. Without it, a new stack reserves none and each render runs up to 90% of the account's unreserved concurrency; a redeploy keeps the stack's current reservation; `none` removes it |
30723072
| `--memory` | `10240` | Lambda memory in MB |
30733073
| `--chrome-source` | `sparticuz` | `sparticuz` or `chrome-headless-shell` |
3074-
| `--video-arch` | `arm64` | `arm64` runs the plan and the chunks on an arm64 container-image function, pushed to an ECR repository named `<stack>-video`; audio and assemble stay on x86. Needs `sparticuz`. `x86_64` runs everything on the x86 function |
3074+
| `--video-arch` | `arm64` | `arm64` runs the plan and the chunks on an arm64 container-image function, pushed to an ECR repository named `<stack>-video`; audio and assemble stay on x86. The image runs its own `chrome-headless-shell`; the handler ZIP it is built from needs `sparticuz`. `x86_64` runs everything on the x86 function |
30753075
| `--skip-build` | off | Reuse the existing `handler.zip` |
30763076
| `--no-warm` | warm | Skip the one warm-up call to the video function after deploy, which loads its container image so the first render is not the one that waits for it |
30773077

‎examples/aws-lambda/template.yaml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ Parameters:
5353
Description: >-
5454
Which Chrome runtime the bundled ZIP was built with. Must match the
5555
`--source=` flag passed to `build-zip.ts`. The handler reads this
56-
via the HYPERFRAMES_LAMBDA_CHROME_SOURCE env var at boot.
56+
via the HYPERFRAMES_LAMBDA_CHROME_SOURCE env var at boot. The arm64
57+
video image always runs its own chrome-headless-shell.
5758
5859
ChunkInvocationAlarmThreshold:
5960
Type: Number
@@ -75,6 +76,7 @@ Parameters:
7576
Conditions:
7677
HasReservedConcurrency: !Not [!Equals [!Ref ReservedConcurrency, -1]]
7778
HasVideoFunction: !Not [!Equals [!Ref VideoImageUri, ""]]
79+
BundlesChromeHeadlessShell: !Equals [!Ref ChromeSource, chrome-headless-shell]
7880

7981
Globals:
8082
Function:
@@ -94,6 +96,11 @@ Globals:
9496
Variables:
9597
NODE_OPTIONS: "--enable-source-maps"
9698
HYPERFRAMES_LAMBDA_CHROME_SOURCE: !Ref ChromeSource
99+
# Where build-zip.ts --source=chrome-headless-shell puts the shell (BUNDLED_SHELL_PATH).
100+
HYPERFRAMES_LAMBDA_CHROME_PATH: !If
101+
- BundlesChromeHeadlessShell
102+
- /var/task/chrome-headless-shell-linux64/chrome-headless-shell
103+
- !Ref AWS::NoValue
97104

98105
Resources:
99106
# ── S3 bucket for plan tarballs, chunk outputs, and final renders ───────
@@ -214,7 +221,6 @@ Resources:
214221
MemorySize: !Ref LambdaMemoryMb
215222
Timeout: !Ref LambdaTimeoutSec
216223
ReservedConcurrency: !Ref ReservedConcurrency
217-
ChromeSource: !Ref ChromeSource
218224
Tags:
219225
- Key: Project
220226
Value: !Ref ProjectName

‎examples/aws-lambda/video-function.yaml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Parameters:
1717
Type: Number
1818
ReservedConcurrency:
1919
Type: Number
20-
ChromeSource:
21-
Type: String
2220

2321
Conditions:
2422
HasReservedConcurrency: !Not [!Equals [!Ref ReservedConcurrency, -1]]
@@ -94,8 +92,8 @@ Resources:
9492
Mode: Active
9593
Environment:
9694
Variables:
95+
# No HYPERFRAMES_LAMBDA_CHROME_SOURCE or _PATH: the image sets them for the Chrome it installs.
9796
NODE_OPTIONS: "--enable-source-maps"
98-
HYPERFRAMES_LAMBDA_CHROME_SOURCE: !Ref ChromeSource
9997
TMPDIR: /tmp
10098
HYPERFRAMES_RENDER_BUCKET: !Ref RenderBucket
10199
HYPERFRAMES_LAMBDA_RESERVED_CONCURRENCY: !Ref ReservedConcurrency

‎packages/aws-lambda/README.md‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The package supports two Chromium sources:
9393
| Source | Default | Size | When to pick it |
9494
| ------------------------------- | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------- |
9595
| `@sparticuz/chromium` | yes | ~70 MiB compressed | Lambda. Decompresses into `/tmp` at runtime; the rest of the ecosystem already uses it for headless-Chrome-in-Lambda. |
96-
| Bundled `chrome-headless-shell` | no | ~140 MiB | Fallback. Used if `@sparticuz/chromium` ever drops `HeadlessExperimental.beginFrame` support. |
96+
| Bundled `chrome-headless-shell` | no | ~296 MB | Fallback. Used if `@sparticuz/chromium` ever drops `HeadlessExperimental.beginFrame` support. |
9797

9898
Pick the source at build time:
9999

@@ -102,9 +102,17 @@ bun run --cwd packages/aws-lambda build:zip
102102
bun run --cwd packages/aws-lambda build:zip -- --source=chrome-headless-shell
103103
```
104104

105-
The handler reads `HYPERFRAMES_LAMBDA_CHROME_SOURCE` at boot. The build
106-
script sets that env var via Lambda function configuration in
107-
`examples/aws-lambda/template.yaml`.
105+
The handler reads `HYPERFRAMES_LAMBDA_CHROME_SOURCE` at boot, and for
106+
`chrome-headless-shell` the executable from `HYPERFRAMES_LAMBDA_CHROME_PATH`.
107+
`examples/aws-lambda/template.yaml` and the CDK construct set both from the
108+
Chrome source. The build stages the whole shell folder (the executable needs
109+
its ICU data and `.pak` files beside it), which is over Lambda's 250 MiB
110+
unzipped limit for a ZIP function, so the x86 ZIP ships `@sparticuz/chromium`.
111+
112+
The arm64 video image (`image/Dockerfile`, `video` target) does not use
113+
`@sparticuz/chromium`: it installs Chrome for Testing's linux-arm64
114+
`chrome-headless-shell` folder, pinned by version and sha256, with the shared
115+
libraries and fonts it needs, and sets both env vars itself.
108116

109117
## BeginFrame regression guard
110118

‎packages/aws-lambda/image/Dockerfile‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,26 @@ COPY --from=check /check.txt /hf-media-check.txt
3737

3838
# The video function. /var/task comes from scripts/stage-arm64-image.ts as the `task` build context:
3939
# docker buildx build --platform linux/arm64 --target video --build-context task=<out>/task packages/aws-lambda/image
40-
# Copy only, so any host builds it without emulation.
40+
# Its Chrome is Chrome for Testing's linux-arm64 chrome-headless-shell, the whole folder: the executable
41+
# alone finds no ICU data or .pak resources. The base has none of the shared libraries the shell links
42+
# and no fonts, so they come from the base's own repository; this RUN needs an arm64 host or emulation.
43+
# Bump the version and the archive's sha256 together, with the rest of the repo's pins.
4144
FROM ${BASE} AS video
45+
ARG CHROME_HEADLESS_SHELL_VERSION=158.0.8127.36
46+
ARG CHROME_HEADLESS_SHELL_SHA256=176ee5c55486c22de43128871189061365ea28e881fc96016fd18e7cb59437c8
47+
COPY fetch.sh /fetch.sh
48+
RUN . /fetch.sh && retry microdnf install -y --nodocs --setopt=install_weak_deps=0 --releasever=2023.12.20260914 \
49+
alsa-lib at-spi2-atk at-spi2-core atk dbus-libs expat fontconfig libX11 libXcomposite libXdamage \
50+
libXext libXfixes libXrandr libxcb libxkbcommon liberation-fonts mesa-libgbm nspr nss nss-util \
51+
systemd-libs unzip && \
52+
curl -fsSL --retry 5 --retry-all-errors --retry-delay 3 --connect-timeout 20 --max-time 600 -o /tmp/chs.zip \
53+
"https://storage.googleapis.com/chrome-for-testing-public/${CHROME_HEADLESS_SHELL_VERSION}/linux-arm64/chrome-headless-shell-linux-arm64.zip" && \
54+
echo "${CHROME_HEADLESS_SHELL_SHA256} /tmp/chs.zip" | sha256sum -c - && \
55+
unzip -q /tmp/chs.zip -d /opt && rm /tmp/chs.zip /fetch.sh && \
56+
microdnf remove -y unzip && microdnf clean all && \
57+
/opt/chrome-headless-shell-linux-arm64/chrome-headless-shell --version | grep -F "${CHROME_HEADLESS_SHELL_VERSION}"
58+
# src/chromium.ts launches this executable.
59+
ENV HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell \
60+
HYPERFRAMES_LAMBDA_CHROME_PATH=/opt/chrome-headless-shell-linux-arm64/chrome-headless-shell
4261
COPY --from=task / /var/task/
4362
CMD ["handler.handler"]

0 commit comments

Comments
 (0)