mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
fix(aws-lambda): match the shell to its own pin, ship only hashed files, refuse the shell ZIP in CDK and SAM (#8173)
* fix(aws-lambda): match the shell to its own pin, ship only hashed files, refuse the shell ZIP in CDK and SAM Review follow-ups to the pinned shell route: - build-zip --source=chrome-headless-shell accepts the folder only when its digest is pinned for this version, not for any pinned build. - It leaves out the files the digest skips (debug.log and chrome_debug.log, which Chrome writes as it runs), so nothing unhashed ships. - The CDK construct throws on chromeSource "chrome-headless-shell" and the SAM template allows only sparticuz, as lambda deploy already refused it: a shell ZIP cannot fit a function. The CHROME_PATH wiring for that ZIP is gone with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(aws-lambda): raise the packed size budget to 82,000 bytes The shipped build-zip script now checks the shell against its own version's pin and skips the files the digest leaves out. That takes the tarball to 81,378 bytes in CI, over the 80,500 budget's 1% tolerance; main was already within about 200 bytes of it. 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:
co-authored by
Claude Opus 5.5
parent
9acf268680
commit
61d65e7177
@@ -31,7 +31,6 @@ 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,
|
||||
@@ -411,44 +410,15 @@ describe("HyperframesRenderStack — snapshot", () => {
|
||||
).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",
|
||||
it("refuses a chrome-headless-shell ZIP, which cannot fit a function, in CDK and SAM", () => {
|
||||
expect(() => doSynth(undefined, "chrome-headless-shell")).toThrow(/does not fit a Lambda ZIP/);
|
||||
const sam = readExampleTemplate("template.yaml");
|
||||
const parameters = requireRecordProperty(sam, "Parameters", "SAM parameters");
|
||||
const chromeSource = requireRecordProperty(parameters, "ChromeSource", "ChromeSource");
|
||||
expect(chromeSource.AllowedValues).toEqual(["sparticuz"]);
|
||||
expect(envNames(sam, "Globals", "Function", "Environment", "Variables")).not.toContain(
|
||||
"HYPERFRAMES_LAMBDA_CHROME_PATH",
|
||||
);
|
||||
expect(conditions.BundlesChromeHeadlessShell).toEqual([
|
||||
"ChromeSource",
|
||||
"chrome-headless-shell",
|
||||
]);
|
||||
}, 30000);
|
||||
|
||||
it("lets the render function abort the multipart uploads its S3 stitch starts", () => {
|
||||
|
||||
@@ -30,7 +30,6 @@ 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}. */
|
||||
@@ -43,7 +42,7 @@ export interface HyperframesRenderStackProps {
|
||||
lambdaTimeoutSec?: number;
|
||||
/** Lambda reserved concurrency cap. `undefined` = unreserved (account default). */
|
||||
reservedConcurrency?: number;
|
||||
/** Which Chrome runtime was bundled into the handler ZIP. Default `"sparticuz"`; a shell ZIP is over Lambda's limit. */
|
||||
/** Which Chrome runtime was bundled into the handler ZIP. Only `"sparticuz"`: a shell ZIP is over Lambda's limit. */
|
||||
chromeSource?: "sparticuz" | "chrome-headless-shell";
|
||||
/** Threshold for the runaway-invocations alarm. Default 1000 invocations/hour. */
|
||||
chunkInvocationAlarmThreshold?: number;
|
||||
@@ -63,15 +62,14 @@ 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(
|
||||
function zipChromeSource(
|
||||
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,
|
||||
};
|
||||
): "sparticuz" {
|
||||
if (source === "sparticuz") return source;
|
||||
throw new Error(
|
||||
"[HyperframesRenderStack] chromeSource chrome-headless-shell does not fit a Lambda ZIP function, so the " +
|
||||
"handler ZIP ships @sparticuz/chromium. The arm64 video image runs chrome-headless-shell.",
|
||||
);
|
||||
}
|
||||
|
||||
export class HyperframesRenderStack extends Construct {
|
||||
@@ -88,7 +86,7 @@ export class HyperframesRenderStack extends Construct {
|
||||
const projectName = props.projectName ?? "hyperframes";
|
||||
const memorySize = props.lambdaMemoryMb ?? DEFAULT_MEMORY_MB;
|
||||
const timeoutSec = props.lambdaTimeoutSec ?? DEFAULT_TIMEOUT_SEC;
|
||||
const chromeSource = props.chromeSource ?? DEFAULT_CHROME_SOURCE;
|
||||
const chromeSource = zipChromeSource(props.chromeSource ?? DEFAULT_CHROME_SOURCE);
|
||||
const alarmThreshold = props.chunkInvocationAlarmThreshold ?? DEFAULT_ALARM_THRESHOLD;
|
||||
const handlerZipPath = props.handlerZipPath ?? defaultHandlerZipPath();
|
||||
|
||||
@@ -129,7 +127,7 @@ export class HyperframesRenderStack extends Construct {
|
||||
environment: {
|
||||
NODE_OPTIONS: "--enable-source-maps",
|
||||
TMPDIR: "/tmp",
|
||||
...chromeEnvironment(chromeSource),
|
||||
HYPERFRAMES_LAMBDA_CHROME_SOURCE: chromeSource,
|
||||
HYPERFRAMES_RENDER_BUCKET: this.bucket.bucketName,
|
||||
HYPERFRAMES_LAMBDA_RESERVED_CONCURRENCY: String(props.reservedConcurrency ?? -1),
|
||||
HYPERFRAMES_STITCH_FUNCTION: `${projectName}-render`,
|
||||
|
||||
@@ -39,7 +39,6 @@ import { existsSync } from "node:fs";
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user