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>
This commit is contained in:
James Russo
2026-11-18 09:07:46 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 3b79b1858e
commit 81d73d2278
27 changed files with 394 additions and 202 deletions
@@ -31,8 +31,12 @@ import {
CONTENT_STORE_REFRESH_AFTER_DAYS,
CONTENT_STORE_RETENTION_DAYS,
} from "../contentStore.js";
import { BUNDLED_SHELL_PATH } from "../chromium.js";
import { SITE_MANIFEST_INVALID } from "../siteManifest.js";
import { HyperframesRenderStack } from "./HyperframesRenderStack.js";
import {
HyperframesRenderStack,
type HyperframesRenderStackProps,
} from "./HyperframesRenderStack.js";
// CDK synth + Template.fromStack is slow on cold start in CI (~5-8s on
// the first call). The default bun:test 5s timeout trips it on the
@@ -86,7 +90,10 @@ const EXPECTED_NON_RETRYABLE_ERRORS = new Set([
"SITE_MANIFEST_INVALID",
]);
function doSynth(reservedConcurrency?: number): {
function doSynth(
reservedConcurrency?: number,
chromeSource?: HyperframesRenderStackProps["chromeSource"],
): {
template: Template;
definition: { States: Record<string, unknown>; StartAt: string };
} {
@@ -97,6 +104,7 @@ function doSynth(reservedConcurrency?: number): {
new HyperframesRenderStack(stack, "Render", {
handlerZipPath: join(zipDir, "handler.zip"),
reservedConcurrency,
chromeSource,
});
const template = Template.fromStack(stack);
const stateMachine = Object.values(
@@ -389,18 +397,60 @@ describe("HyperframesRenderStack — snapshot", () => {
);
});
it("gives the nested arm64 video function every environment variable the render function gets", () => {
it("gives the nested arm64 video function every environment variable the render function gets but its Chrome's", () => {
const sam = readExampleTemplate("template.yaml");
// The image sets these for the chrome-headless-shell it installs; a function value would override them.
const imageOwned = ["HYPERFRAMES_LAMBDA_CHROME_SOURCE", "HYPERFRAMES_LAMBDA_CHROME_PATH"];
const render = [
...envNames(sam, "Globals", "Function", "Environment", "Variables"),
...envNames(sam, "Resources", "RenderFunction", "Properties", "Environment", "Variables"),
];
].filter((name) => !imageOwned.includes(name));
const video = readExampleTemplate("video-function.yaml");
expect(
envNames(video, "Resources", "Function", "Properties", "Environment", "Variables").sort(),
).toEqual([...new Set(render)].sort());
});
it("points a chrome-headless-shell ZIP at its bundled shell, in CDK and SAM", () => {
const chromeEnv = (synthed: ReturnType<typeof doSynth>) => {
const fn = Object.values(synthed.template.findResources("AWS::Lambda::Function"))[0] as {
Properties: { Environment: { Variables: Record<string, unknown> } };
};
const vars = fn.Properties.Environment.Variables;
return [vars.HYPERFRAMES_LAMBDA_CHROME_SOURCE, vars.HYPERFRAMES_LAMBDA_CHROME_PATH];
};
expect(chromeEnv(SYNTHED)).toEqual(["sparticuz", undefined]);
expect(chromeEnv(doSynth(undefined, "chrome-headless-shell"))).toEqual([
"chrome-headless-shell",
BUNDLED_SHELL_PATH,
]);
const globals = requireRecordProperty(
requireRecordProperty(
requireRecordProperty(readExampleTemplate("template.yaml"), "Globals", "SAM globals"),
"Function",
"SAM function globals",
),
"Environment",
"SAM global environment",
) as { Variables: Record<string, unknown> };
// The YAML parser drops the !If and !Ref tags and keeps [condition, then, else].
expect(globals.Variables.HYPERFRAMES_LAMBDA_CHROME_PATH).toEqual([
"BundlesChromeHeadlessShell",
BUNDLED_SHELL_PATH,
"AWS::NoValue",
]);
const conditions = requireRecordProperty(
readExampleTemplate("template.yaml"),
"Conditions",
"SAM conditions",
);
expect(conditions.BundlesChromeHeadlessShell).toEqual([
"ChromeSource",
"chrome-headless-shell",
]);
}, 30000);
it("lets the render function abort the multipart uploads its S3 stitch starts", () => {
const cdkPolicies = JSON.stringify(SYNTHED.template.findResources("AWS::IAM::Policy"));
expect(cdkPolicies).toContain("s3:Abort*");
@@ -30,6 +30,7 @@ import * as s3 from "aws-cdk-lib/aws-s3";
import * as sfn from "aws-cdk-lib/aws-stepfunctions";
import * as tasks from "aws-cdk-lib/aws-stepfunctions-tasks";
import { Construct } from "constructs";
import { BUNDLED_SHELL_PATH } from "../chromium.js";
import { CONTENT_STORE_PREFIX, CONTENT_STORE_RETENTION_DAYS } from "../contentStore.js";
/** Construction-time props for {@link HyperframesRenderStack}. */
@@ -62,6 +63,17 @@ const DEFAULT_TIMEOUT_SEC = 900;
const DEFAULT_CHROME_SOURCE = "sparticuz";
const DEFAULT_ALARM_THRESHOLD = 1000;
/** The handler's Chrome source, and for the bundled shell, where build-zip.ts put it. */
function chromeEnvironment(
source: NonNullable<HyperframesRenderStackProps["chromeSource"]>,
): Record<string, string> {
if (source === "sparticuz") return { HYPERFRAMES_LAMBDA_CHROME_SOURCE: source };
return {
HYPERFRAMES_LAMBDA_CHROME_SOURCE: source,
HYPERFRAMES_LAMBDA_CHROME_PATH: BUNDLED_SHELL_PATH,
};
}
export class HyperframesRenderStack extends Construct {
/** S3 bucket for plan tarballs, chunk outputs, and final renders. */
readonly bucket: s3.Bucket;
@@ -117,7 +129,7 @@ export class HyperframesRenderStack extends Construct {
environment: {
NODE_OPTIONS: "--enable-source-maps",
TMPDIR: "/tmp",
HYPERFRAMES_LAMBDA_CHROME_SOURCE: chromeSource,
...chromeEnvironment(chromeSource),
HYPERFRAMES_RENDER_BUCKET: this.bucket.bucketName,
HYPERFRAMES_LAMBDA_RESERVED_CONCURRENCY: String(props.reservedConcurrency ?? -1),
HYPERFRAMES_STITCH_FUNCTION: `${projectName}-render`,
+8 -5
View File
@@ -18,11 +18,12 @@
* 2. A bundled `chrome-headless-shell` binary (fallback). If
* `@sparticuz/chromium`'s build ever drops `HeadlessExperimental`
* support, we fall back to the same `chrome-headless-shell` build
* the K8s deploy uses. The fallback raises the ZIP from ~70 MB
* Chrome to ~140 MB Chrome — still well under 250 MB.
* the K8s deploy uses. The whole shell folder (~296 MB unzipped)
* does not fit a ZIP function's 250 MiB limit; the arm64 container
* image installs it instead.
*
* The runtime path is selected by the `HYPERFRAMES_LAMBDA_CHROME_SOURCE`
* env var (set by `build-zip.ts`):
* env var (set by the SAM template, the CDK stack, or the arm64 image):
*
* "sparticuz" → use `@sparticuz/chromium.executablePath()`
* "chrome-headless-shell" → use `process.env.HYPERFRAMES_LAMBDA_CHROME_PATH`
@@ -37,6 +38,9 @@ import { existsSync } from "node:fs";
/** Discriminator for the two supported Chrome sources. */
export type ChromeSource = "sparticuz" | "chrome-headless-shell";
export const BUNDLED_SHELL_DIR = "chrome-headless-shell-linux64";
export const BUNDLED_SHELL_PATH = `/var/task/${BUNDLED_SHELL_DIR}/chrome-headless-shell`;
/**
* Thrown when the Chrome binary resolver can't produce a usable path.
* The class name is the SFN `Retry: { ErrorEquals: [...] }` discriminator —
@@ -45,8 +49,7 @@ export type ChromeSource = "sparticuz" | "chrome-headless-shell";
export class ChromeBinaryUnavailableError extends Error {
// Lambda's runtime serializes the error envelope's `errorType` from
// `err.name`; this class-field override sets it across the structured
// clone. Read indirectly; fallow can't follow.
// fallow-ignore-next-line unused-class-member
// clone.
override readonly name = "ChromeBinaryUnavailableError";
readonly source: ChromeSource;
readonly resolvedPath: string | null;