Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lambda-arm64-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- "packages/aws-lambda/image/**"
- "packages/aws-lambda/hf-media-linux-aarch64.sha256"
- "packages/aws-lambda/scripts/stage-arm64-image.ts"
# A @sparticuz/chromium bump or a ZIP layout change must re-stage the image.
# A dependency bump or a ZIP layout change must re-stage the image.
- "packages/aws-lambda/package.json"
- "packages/aws-lambda/scripts/build-zip.ts"
- "packages/aws-lambda/scripts/runtimeLock.ts"
Expand Down
86 changes: 74 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,73 @@ jobs:
path: packages/aws-lambda/dist/handler.zip
if-no-files-found: error

# The video stage installs Chrome's system libraries with microdnf, so it builds on ARM, not under emulation.
lambda-video-image:
name: Lambda video image
needs: [release-source, lambda-arm64-ffmpeg, lambda-handler-zip]
runs-on: ubuntu-24.04-arm
timeout-minutes: 30
permissions:
contents: read
env:
EXPECTED_RELEASE_SHA: ${{ needs.release-source.outputs.sha }}
if: needs.release-source.outputs.sha != ''
outputs:
sha256: ${{ steps.image.outputs.sha256 }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ env.EXPECTED_RELEASE_SHA }}
persist-credentials: false
- name: Verify immutable release checkout
run: |
ACTUAL_SHA="$(git rev-parse HEAD)"
EXPECTED_COMMIT_SHA="$(git rev-parse "${EXPECTED_RELEASE_SHA}^{commit}")"
if [ "$ACTUAL_SHA" != "$EXPECTED_COMMIT_SHA" ]; then
echo "::error::Expected release commit $EXPECTED_COMMIT_SHA, checked out $ACTUAL_SHA"
exit 1
fi
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
no-cache: true
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: hyperframes-lambda-handler-zip
path: dist/lambda-handler-build
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: hf-media-linux-aarch64
path: dist/hf-media
- name: Build Lambda video image
id: image
env:
EXPECTED_ZIP_SHA256: ${{ needs.lambda-handler-zip.outputs.sha256 }}
run: |
ACTUAL_ZIP_SHA256="$(sha256sum dist/lambda-handler-build/handler.zip | cut -d' ' -f1)"
if [ -z "$EXPECTED_ZIP_SHA256" ] || [ "$ACTUAL_ZIP_SHA256" != "$EXPECTED_ZIP_SHA256" ]; then
echo "::error::Lambda handler zip sha256 $ACTUAL_ZIP_SHA256 does not match the build job's $EXPECTED_ZIP_SHA256"
exit 1
fi
bun packages/aws-lambda/scripts/stage-arm64-image.ts --zip=dist/lambda-handler-build/handler.zip \
--ffmpeg=dist/hf-media/hf-media-linux-aarch64.tar.gz --out=dist/arm64-image
# OCI export needs a docker-container builder; no attestations, so index.json lists one image.
docker buildx create --use
docker buildx build --progress=plain --platform linux/arm64 --target video \
--provenance=false --sbom=false --build-context task=dist/arm64-image/task \
--output type=oci,dest=dist/hyperframes-lambda-video-arm64.oci.tar packages/aws-lambda/image
echo "sha256=$(sha256sum dist/hyperframes-lambda-video-arm64.oci.tar | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: hyperframes-lambda-video-arm64
overwrite: true
path: dist/hyperframes-lambda-video-arm64.oci.tar
if-no-files-found: error

pack:
name: Build and pack
outputs:
bundle_id: ${{ steps.previous_bundle.outputs.artifact || steps.bundle.outputs.artifact-id }}
needs: [release-source, lambda-arm64-ffmpeg, lambda-handler-zip]
needs: [release-source, lambda-handler-zip, lambda-video-image]
runs-on: ubuntu-latest
timeout-minutes: 30
# Every build and lifecycle script of the release commit runs here, with a
Expand Down Expand Up @@ -385,24 +447,24 @@ jobs:
rm -rf dist/lambda-handler-build
bun packages/aws-lambda/scripts/pin-handler-zip.ts
# lambda-video-image built it on ARM from the same zip sha pinned above.
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
if: steps.previous_bundle.outputs.artifact == ''
with:
name: hf-media-linux-aarch64
path: dist/hf-media
name: hyperframes-lambda-video-arm64
path: dist

# Built from the zip pinned above. The video stage only copies files, so no emulation is needed.
- name: Build Lambda video image
- name: Pin Lambda video image
if: steps.previous_bundle.outputs.artifact == ''
id: lambda_video_image
env:
EXPECTED_SHA256: ${{ needs.lambda-video-image.outputs.sha256 }}
run: |
bun packages/aws-lambda/scripts/stage-arm64-image.ts --zip=dist/hyperframes-lambda-handler.zip \
--ffmpeg=dist/hf-media/hf-media-linux-aarch64.tar.gz --out=dist/arm64-image
# OCI export needs a docker-container builder; no attestations, so index.json lists one image.
docker buildx create --use
docker buildx build --progress=plain --platform linux/arm64 --target video \
--provenance=false --sbom=false --build-context task=dist/arm64-image/task \
--output type=oci,dest=dist/hyperframes-lambda-video-arm64.oci.tar packages/aws-lambda/image
ACTUAL_SHA256="$(sha256sum dist/hyperframes-lambda-video-arm64.oci.tar | cut -d' ' -f1)"
if [ -z "$EXPECTED_SHA256" ] || [ "$ACTUAL_SHA256" != "$EXPECTED_SHA256" ]; then
echo "::error::Lambda video image sha256 $ACTUAL_SHA256 does not match the build job's $EXPECTED_SHA256"
exit 1
fi
bun packages/aws-lambda/scripts/pin-handler-zip.ts --video-image
- run: bun run verify:packed-manifests
Expand Down
7 changes: 2 additions & 5 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/deploy/aws-lambda.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The stack's bucket expires objects under `cas/sha256/` 30 days after they were l

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

`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.
`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.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/packages/aws-lambda.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The Lambda adapter wraps the distributed producer primitives behind one dispatch

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.

The handler uses `@sparticuz/chromium` by default, with a build-time fallback for bundling `chrome-headless-shell` directly when needed.
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`.

### Page network restriction

Expand Down
2 changes: 1 addition & 1 deletion docs/packages/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3071,7 +3071,7 @@ deploy:
| `--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 |
| `--memory` | `10240` | Lambda memory in MB |
| `--chrome-source` | `sparticuz` | `sparticuz` or `chrome-headless-shell` |
| `--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 |
| `--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 |
| `--skip-build` | off | Reuse the existing `handler.zip` |
| `--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 |

Expand Down
10 changes: 8 additions & 2 deletions examples/aws-lambda/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Parameters:
Description: >-
Which Chrome runtime the bundled ZIP was built with. Must match the
`--source=` flag passed to `build-zip.ts`. The handler reads this
via the HYPERFRAMES_LAMBDA_CHROME_SOURCE env var at boot.
via the HYPERFRAMES_LAMBDA_CHROME_SOURCE env var at boot. The arm64
video image always runs its own chrome-headless-shell.
ChunkInvocationAlarmThreshold:
Type: Number
Expand All @@ -75,6 +76,7 @@ Parameters:
Conditions:
HasReservedConcurrency: !Not [!Equals [!Ref ReservedConcurrency, -1]]
HasVideoFunction: !Not [!Equals [!Ref VideoImageUri, ""]]
BundlesChromeHeadlessShell: !Equals [!Ref ChromeSource, chrome-headless-shell]

Globals:
Function:
Expand All @@ -94,6 +96,11 @@ Globals:
Variables:
NODE_OPTIONS: "--enable-source-maps"
HYPERFRAMES_LAMBDA_CHROME_SOURCE: !Ref ChromeSource
# Where build-zip.ts --source=chrome-headless-shell puts the shell (BUNDLED_SHELL_PATH).
HYPERFRAMES_LAMBDA_CHROME_PATH: !If
- BundlesChromeHeadlessShell
- /var/task/chrome-headless-shell-linux64/chrome-headless-shell
- !Ref AWS::NoValue

Resources:
# ── S3 bucket for plan tarballs, chunk outputs, and final renders ───────
Expand Down Expand Up @@ -214,7 +221,6 @@ Resources:
MemorySize: !Ref LambdaMemoryMb
Timeout: !Ref LambdaTimeoutSec
ReservedConcurrency: !Ref ReservedConcurrency
ChromeSource: !Ref ChromeSource
Tags:
- Key: Project
Value: !Ref ProjectName
Expand Down
4 changes: 1 addition & 3 deletions examples/aws-lambda/video-function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Parameters:
Type: Number
ReservedConcurrency:
Type: Number
ChromeSource:
Type: String

Conditions:
HasReservedConcurrency: !Not [!Equals [!Ref ReservedConcurrency, -1]]
Expand Down Expand Up @@ -94,8 +92,8 @@ Resources:
Mode: Active
Environment:
Variables:
# No HYPERFRAMES_LAMBDA_CHROME_SOURCE or _PATH: the image sets them for the Chrome it installs.
NODE_OPTIONS: "--enable-source-maps"
HYPERFRAMES_LAMBDA_CHROME_SOURCE: !Ref ChromeSource
TMPDIR: /tmp
HYPERFRAMES_RENDER_BUCKET: !Ref RenderBucket
HYPERFRAMES_LAMBDA_RESERVED_CONCURRENCY: !Ref ReservedConcurrency
Expand Down
16 changes: 12 additions & 4 deletions packages/aws-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The package supports two Chromium sources:
| Source | Default | Size | When to pick it |
| ------------------------------- | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------- |
| `@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. |
| Bundled `chrome-headless-shell` | no | ~140 MiB | Fallback. Used if `@sparticuz/chromium` ever drops `HeadlessExperimental.beginFrame` support. |
| Bundled `chrome-headless-shell` | no | ~296 MB | Fallback. Used if `@sparticuz/chromium` ever drops `HeadlessExperimental.beginFrame` support. |

Pick the source at build time:

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

The handler reads `HYPERFRAMES_LAMBDA_CHROME_SOURCE` at boot. The build
script sets that env var via Lambda function configuration in
`examples/aws-lambda/template.yaml`.
The handler reads `HYPERFRAMES_LAMBDA_CHROME_SOURCE` at boot, and for
`chrome-headless-shell` the executable from `HYPERFRAMES_LAMBDA_CHROME_PATH`.
`examples/aws-lambda/template.yaml` and the CDK construct set both from the
Chrome source. The build stages the whole shell folder (the executable needs
its ICU data and `.pak` files beside it), which is over Lambda's 250 MiB
unzipped limit for a ZIP function, so the x86 ZIP ships `@sparticuz/chromium`.

The arm64 video image (`image/Dockerfile`, `video` target) does not use
`@sparticuz/chromium`: it installs Chrome for Testing's linux-arm64
`chrome-headless-shell` folder, pinned by version and sha256, with the shared
libraries and fonts it needs, and sets both env vars itself.

## BeginFrame regression guard

Expand Down
21 changes: 20 additions & 1 deletion packages/aws-lambda/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,26 @@ COPY --from=check /check.txt /hf-media-check.txt

# The video function. /var/task comes from scripts/stage-arm64-image.ts as the `task` build context:
# docker buildx build --platform linux/arm64 --target video --build-context task=<out>/task packages/aws-lambda/image
# Copy only, so any host builds it without emulation.
# Its Chrome is Chrome for Testing's linux-arm64 chrome-headless-shell, the whole folder: the executable
# alone finds no ICU data or .pak resources. The base has none of the shared libraries the shell links
# and no fonts, so they come from the base's own repository; this RUN needs an arm64 host or emulation.
# Bump the version and the archive's sha256 together, with the rest of the repo's pins.
FROM ${BASE} AS video
ARG CHROME_HEADLESS_SHELL_VERSION=158.0.8127.36
ARG CHROME_HEADLESS_SHELL_SHA256=176ee5c55486c22de43128871189061365ea28e881fc96016fd18e7cb59437c8
COPY fetch.sh /fetch.sh
RUN . /fetch.sh && retry microdnf install -y --nodocs --setopt=install_weak_deps=0 --releasever=2023.12.20260914 \
alsa-lib at-spi2-atk at-spi2-core atk dbus-libs expat fontconfig libX11 libXcomposite libXdamage \
libXext libXfixes libXrandr libxcb libxkbcommon liberation-fonts mesa-libgbm nspr nss nss-util \
systemd-libs unzip && \
curl -fsSL --retry 5 --retry-all-errors --retry-delay 3 --connect-timeout 20 --max-time 600 -o /tmp/chs.zip \
"https://storage.googleapis.com/chrome-for-testing-public/${CHROME_HEADLESS_SHELL_VERSION}/linux-arm64/chrome-headless-shell-linux-arm64.zip" && \
echo "${CHROME_HEADLESS_SHELL_SHA256} /tmp/chs.zip" | sha256sum -c - && \
unzip -q /tmp/chs.zip -d /opt && rm /tmp/chs.zip /fetch.sh && \
microdnf remove -y unzip && microdnf clean all && \
/opt/chrome-headless-shell-linux-arm64/chrome-headless-shell --version | grep -F "${CHROME_HEADLESS_SHELL_VERSION}"
# src/chromium.ts launches this executable.
ENV HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell \
HYPERFRAMES_LAMBDA_CHROME_PATH=/opt/chrome-headless-shell-linux-arm64/chrome-headless-shell
COPY --from=task / /var/task/
CMD ["handler.handler"]
9 changes: 4 additions & 5 deletions packages/aws-lambda/image/smoke-video.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// 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.
// AWS_EXECUTION_ENV as Lambda does: the bundled ffmpeg answers and the image's chrome-headless-shell
// renders, found where src/chromium.ts finds it and launched with the engine's Lambda flags.
import { execFileSync } from "node:child_process";
import chromium from "@sparticuz/chromium";
import puppeteer from "puppeteer-core";

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,
executablePath: process.env.HYPERFRAMES_LAMBDA_CHROME_PATH,
args: ["--no-sandbox", "--disable-setuid-sandbox", "--no-zygote", "--disable-dev-shm-usage"],
});
try {
const page = await browser.newPage();
Expand Down
3 changes: 1 addition & 2 deletions packages/aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@
"@aws-sdk/client-sfn": "^3.1146.0",
"@aws-sdk/s3-request-presigner": "3.1146.0",
"@hyperframes/producer": "workspace:^",
"@sparticuz/chromium": "148.0.0",
"@sparticuz/chromium": "153.0.0",
"ffmpeg-static": "^5.2.0",
"ffprobe-static": "^3.1.0",
"puppeteer-core": "^25.8.0",
"tar": "^7.5.22"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.146",
"@types/node": "^25.0.10",
"@types/tar": "^6.1.13",
"aws-cdk-lib": "^2.130.0",
Expand Down
Loading
Loading