mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
feat(cli): lambda deploy works from the npm install, no repo checkout (#5866)
* feat(cli): lambda deploy works from the npm install, no repo checkout Each release builds the Lambda handler zip on Linux, attaches it to the GitHub release, and pins its URL and sha256 (plus the SAM template) in @hyperframes/aws-lambda before npm publish. Outside a checkout, lambda deploy downloads that zip, refuses it on a sha256 mismatch, and deploys it with the packaged template. With neither a checkout nor a pinned zip it fails up front with one message naming every way out. * fix(cli): lambda deploy test mocks the pinned-handler reader, comments fit the checks * test(cli): sam tests deploy from a SAM directory, not the repo root * chore(aws-lambda): raise the package size budget for the pinned handler template Measured with pnpm@10.17.1 pack on Linux. Release state (prebuilt/ written by pin-handler-zip): 77,307 packed / 285,654 unpacked. CI state (no prebuilt/): 70,104 / 253,390. Packed is the check's 5% headroom over the release size. Unpacked is 292,000 (2.2% over release) because a 5% budget would put the CI pack under the 85% ratchet. * test(cli): anchor the docs link check in the lambda deploy fallback test * fix(cli): lambda deploy logs the verified handler sha256 and keeps a presigned query out of errors * fix(cli): a redirect-limit download error keeps a signed query out of its message * test(cli): the redirect-limit leak test types its rejection * docs(aws-lambda): header comments cut to what the code cannot say * chore(aws-lambda): size budget fits both the CI and the release package
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const root = vi.hoisted(() => ({ value: undefined as string | undefined }));
|
||||
vi.mock("./repoRoot.js", () => ({ repoRoot: () => root.value }));
|
||||
vi.mock("@hyperframes/aws-lambda/sdk", () => ({ prebuiltHandler: () => undefined }));
|
||||
vi.mock("./sam.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("./sam.js")>()),
|
||||
samDeploy: vi.fn(),
|
||||
fetchStackOutputs: vi.fn(() => ({ bucketName: "b", functionName: "f", stateMachineArn: "s" })),
|
||||
}));
|
||||
vi.mock("./state.js", () => ({ DEFAULT_STACK_NAME: "hf", writeStackOutputs: () => "state.json" }));
|
||||
|
||||
const { runDeploy } = await import("./deploy.js");
|
||||
const { samDeploy } = await import("./sam.js");
|
||||
|
||||
let dir: string | undefined;
|
||||
let quiet: { mockRestore(): void };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(samDeploy).mockClear();
|
||||
quiet = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
quiet.mockRestore();
|
||||
root.value = undefined;
|
||||
if (dir) rmSync(dir, { recursive: true, force: true });
|
||||
dir = undefined;
|
||||
});
|
||||
|
||||
describe("runDeploy", () => {
|
||||
it("outside a checkout with no pinned handler, fails with the one message before running SAM", async () => {
|
||||
await expect(runDeploy()).rejects.toThrow(
|
||||
/no prebuilt Lambda handler is available[\s\S]*Docs:/,
|
||||
);
|
||||
expect(samDeploy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("outside a checkout, refuses a Chrome source the prebuilt handler does not bundle", async () => {
|
||||
await expect(runDeploy({ chromeSource: "chrome-headless-shell" })).rejects.toThrow(
|
||||
/needs a hyperframes checkout/,
|
||||
);
|
||||
expect(samDeploy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("inside a checkout, deploys the checkout's template as before", async () => {
|
||||
dir = mkdtempSync(join(tmpdir(), "hf-deploy-checkout-"));
|
||||
const samDir = join(dir, "examples", "aws-lambda");
|
||||
mkdirSync(samDir, { recursive: true });
|
||||
writeFileSync(join(samDir, "template.yaml"), "Resources: {}\n");
|
||||
mkdirSync(join(dir, "packages", "aws-lambda", "dist"), { recursive: true });
|
||||
writeFileSync(join(dir, "packages", "aws-lambda", "dist", "handler.zip"), "zip");
|
||||
root.value = dir;
|
||||
|
||||
await runDeploy({ skipBuild: true });
|
||||
expect(vi.mocked(samDeploy).mock.calls[0]?.[0]).toMatchObject({ samDir });
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* `hyperframes lambda deploy` — build the handler ZIP, sam-deploy the
|
||||
* `hyperframes lambda deploy` — build the handler ZIP (or, outside a
|
||||
* checkout, fetch the adapter's pinned prebuilt one), sam-deploy the
|
||||
* Phase 6a SAM template, and persist the stack outputs locally so the
|
||||
* other lambda subcommands don't need re-derive them.
|
||||
*
|
||||
@@ -9,8 +10,9 @@
|
||||
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { existsSync } from "node:fs";
|
||||
import { join, resolve } from "node:path";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { c } from "../../ui/colors.js";
|
||||
import { stagePrebuiltHandler } from "./prebuiltHandler.js";
|
||||
import { fetchStackOutputs, locateSamTemplate, samDeploy } from "./sam.js";
|
||||
import { repoRoot } from "./repoRoot.js";
|
||||
import { DEFAULT_STACK_NAME, writeStackOutputs } from "./state.js";
|
||||
@@ -41,26 +43,11 @@ export async function runDeploy(args: Partial<DeployArgs> = {}): Promise<void> {
|
||||
skipBuild: args.skipBuild ?? false,
|
||||
};
|
||||
|
||||
const root = repoRoot();
|
||||
// Locate the SAM template up-front so users get a fast, clear error
|
||||
// (not an opaque `sam deploy` failure) when this isn't a checkout.
|
||||
locateSamTemplate(root);
|
||||
|
||||
if (!resolved.skipBuild) {
|
||||
console.log(c.dim("→ Building handler ZIP"));
|
||||
buildHandlerZip(root);
|
||||
} else {
|
||||
const zip = join(root, "packages", "aws-lambda", "dist", "handler.zip");
|
||||
if (!existsSync(zip)) {
|
||||
throw new Error(
|
||||
`--skip-build set but ${zip} does not exist. Run \`bun run --cwd packages/aws-lambda build:zip\` first or drop --skip-build.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const samDir = await prepareSamDir(repoRoot(), resolved);
|
||||
|
||||
console.log(c.dim(`→ sam deploy (stack=${resolved.stackName} region=${resolved.region})`));
|
||||
samDeploy({
|
||||
repoRoot: root,
|
||||
samDir,
|
||||
stackName: resolved.stackName,
|
||||
region: resolved.region,
|
||||
awsProfile: resolved.awsProfile,
|
||||
@@ -114,6 +101,31 @@ export async function runDeploy(args: Partial<DeployArgs> = {}): Promise<void> {
|
||||
console.log(c.dim(`Render with: hyperframes lambda render <project-dir>`));
|
||||
}
|
||||
|
||||
/** Checkout: build the ZIP from source. Otherwise: stage the adapter's pinned prebuilt ZIP. */
|
||||
async function prepareSamDir(root: string | undefined, args: DeployArgs): Promise<string> {
|
||||
if (!root) {
|
||||
if (args.chromeSource !== "sparticuz") {
|
||||
throw new Error(
|
||||
"[lambda deploy] The prebuilt handler bundles sparticuz Chrome; --chrome-source=chrome-headless-shell needs a hyperframes checkout.",
|
||||
);
|
||||
}
|
||||
return stagePrebuiltHandler();
|
||||
}
|
||||
const samDir = dirname(locateSamTemplate(root));
|
||||
if (!args.skipBuild) {
|
||||
console.log(c.dim("→ Building handler ZIP"));
|
||||
buildHandlerZip(root);
|
||||
} else {
|
||||
const zip = join(root, "packages", "aws-lambda", "dist", "handler.zip");
|
||||
if (!existsSync(zip)) {
|
||||
throw new Error(
|
||||
`--skip-build set but ${zip} does not exist. Run \`bun run --cwd packages/aws-lambda build:zip\` first or drop --skip-build.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return samDir;
|
||||
}
|
||||
|
||||
function buildHandlerZip(root: string): void {
|
||||
// bun run --cwd packages/aws-lambda build:zip
|
||||
const result = spawnSync(
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
* rather than re-implementing the empty-and-delete dance here.
|
||||
*/
|
||||
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { c } from "../../ui/colors.js";
|
||||
import { deleteStackOutputs, requireStack } from "./state.js";
|
||||
import { samDelete } from "./sam.js";
|
||||
@@ -22,11 +24,12 @@ export interface DestroyArgs {
|
||||
export async function runDestroy(args: DestroyArgs): Promise<void> {
|
||||
const stack = requireStack(args.stackName);
|
||||
console.log(c.dim(`→ sam delete (stack=${stack.stackName} region=${stack.region})`));
|
||||
const root = repoRoot();
|
||||
// Mirror deploy.ts's AWS_PROFILE env fallback — `AWS_PROFILE=prod
|
||||
// hyperframes lambda destroy` should hit the same account `deploy`
|
||||
// did, not the default credentials chain.
|
||||
samDelete({
|
||||
repoRoot: repoRoot(),
|
||||
samDir: root ? join(root, "examples", "aws-lambda") : tmpdir(),
|
||||
stackName: stack.stackName,
|
||||
region: stack.region,
|
||||
awsProfile: args.awsProfile ?? process.env.AWS_PROFILE,
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { noHandlerMessage, type StageDeps, stagePrebuiltHandler } from "./prebuiltHandler.js";
|
||||
|
||||
const ZIP = Buffer.from("prebuilt handler zip");
|
||||
const SHA = createHash("sha256").update(ZIP).digest("hex");
|
||||
const URL = "https://github.com/heygen-com/hyperframes/releases/download/v9.8.7/x.zip";
|
||||
const dirs: string[] = [];
|
||||
|
||||
function setup(body: Buffer = ZIP) {
|
||||
const root = mkdtempSync(join(tmpdir(), "hf-prebuilt-"));
|
||||
dirs.push(root);
|
||||
const templatePath = join(root, "template.yaml");
|
||||
writeFileSync(templatePath, "CodeUri: handler.zip\n");
|
||||
const downloads: string[] = [];
|
||||
const logs: string[] = [];
|
||||
const deps: StageDeps = {
|
||||
loadAdapter: async () => ({
|
||||
prebuiltHandler: () => ({
|
||||
version: "9.8.7",
|
||||
url: URL,
|
||||
sha256: SHA,
|
||||
bytes: ZIP.length,
|
||||
templatePath,
|
||||
}),
|
||||
}),
|
||||
download: async (url, dest) => {
|
||||
downloads.push(url);
|
||||
writeFileSync(dest, body);
|
||||
},
|
||||
cacheDir: join(root, "cache"),
|
||||
log: (line) => logs.push(line),
|
||||
};
|
||||
return { deps, downloads, logs };
|
||||
}
|
||||
|
||||
function missingModule(): Error {
|
||||
return Object.assign(new Error("Cannot find package '@hyperframes/aws-lambda' imported from x"), {
|
||||
code: "ERR_MODULE_NOT_FOUND",
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe("stagePrebuiltHandler", () => {
|
||||
it("downloads the pinned zip once, then reuses the verified copy beside the template", async () => {
|
||||
const { deps, downloads, logs } = setup();
|
||||
|
||||
const dir = await stagePrebuiltHandler(deps);
|
||||
expect(logs).toContain(`→ Verified sha256 ${SHA}`);
|
||||
expect(dir).toBe(join(deps.cacheDir, `9.8.7-${SHA}`));
|
||||
expect(readFileSync(join(dir, "handler.zip"))).toEqual(ZIP);
|
||||
expect(readFileSync(join(dir, "template.yaml"), "utf-8")).toBe("CodeUri: handler.zip\n");
|
||||
|
||||
expect(await stagePrebuiltHandler(deps)).toBe(dir);
|
||||
expect(downloads).toEqual([URL]);
|
||||
});
|
||||
|
||||
it("re-downloads a cached copy that no longer matches the pin", async () => {
|
||||
const { deps, downloads } = setup();
|
||||
const dir = await stagePrebuiltHandler(deps);
|
||||
writeFileSync(join(dir, "handler.zip"), "tampered");
|
||||
|
||||
await stagePrebuiltHandler(deps);
|
||||
expect(readFileSync(join(dir, "handler.zip"))).toEqual(ZIP);
|
||||
expect(downloads).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("refuses a download whose sha256 does not match and keeps nothing to deploy", async () => {
|
||||
vi.stubEnv("HYPERFRAMES_LAMBDA_HANDLER_URL", "https://b.example/h.zip?X-Amz-Signature=secret");
|
||||
const { deps } = setup(Buffer.from("something else"));
|
||||
|
||||
const refusal = stagePrebuiltHandler(deps);
|
||||
await expect(refusal).rejects.toThrow(
|
||||
/Refusing the handler ZIP from https:\/\/b\.example\/h\.zip: sha256/,
|
||||
);
|
||||
await expect(refusal).rejects.not.toThrow(/secret/);
|
||||
const dir = join(deps.cacheDir, `9.8.7-${SHA}`);
|
||||
expect(existsSync(join(dir, "handler.zip"))).toBe(false);
|
||||
expect(existsSync(join(dir, "handler.zip.download"))).toBe(false);
|
||||
expect(existsSync(join(dir, "template.yaml"))).toBe(false);
|
||||
});
|
||||
|
||||
it("fetches from HYPERFRAMES_LAMBDA_HANDLER_URL when set, still against the pinned sha256", async () => {
|
||||
vi.stubEnv("HYPERFRAMES_LAMBDA_HANDLER_URL", "https://mirror.example/handler.zip");
|
||||
const { deps, downloads } = setup();
|
||||
|
||||
await stagePrebuiltHandler(deps);
|
||||
expect(downloads).toEqual(["https://mirror.example/handler.zip"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("stagePrebuiltHandler with nothing to deploy", () => {
|
||||
it("names the adapter install, the checkout alternative and the docs when the adapter is missing", async () => {
|
||||
const { deps, downloads } = setup();
|
||||
deps.loadAdapter = async () => {
|
||||
throw missingModule();
|
||||
};
|
||||
|
||||
await expect(stagePrebuiltHandler(deps)).rejects.toThrow(noHandlerMessage(false));
|
||||
const message = noHandlerMessage(false);
|
||||
expect(message).toMatch(/npm install -g @hyperframes\/aws-lambda@/);
|
||||
expect(message).toMatch(/HYPERFRAMES_REPO_ROOT/);
|
||||
expect(message).toMatch(/^Docs: https:\/\/hyperframes\.heygen\.com\/deploy\/aws-lambda$/m);
|
||||
expect(downloads).toEqual([]);
|
||||
});
|
||||
|
||||
it("says the installed adapter has no prebuilt handler when it pins none", async () => {
|
||||
const { deps, downloads } = setup();
|
||||
deps.loadAdapter = async () => ({});
|
||||
|
||||
await expect(stagePrebuiltHandler(deps)).rejects.toThrow(noHandlerMessage(true));
|
||||
expect(noHandlerMessage(true)).toMatch(/has no prebuilt handler for its version/);
|
||||
expect(downloads).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,88 @@
|
||||
// `lambda deploy` without a repo checkout: fetch the pinned handler ZIP, verify its sha256 and
|
||||
// stage it beside the packaged SAM template.
|
||||
|
||||
import { createHash } from "node:crypto";
|
||||
import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { downloadFile } from "../../utils/download.js";
|
||||
import { isMissingPackageError } from "../../utils/missingPackage.js";
|
||||
import { VERSION } from "../../version.js";
|
||||
|
||||
const DOCS_URL = "https://hyperframes.heygen.com/deploy/aws-lambda";
|
||||
const HANDLER_CACHE_DIR = join(homedir(), ".cache", "hyperframes", "lambda-handler");
|
||||
|
||||
type AdapterSdk = typeof import("@hyperframes/aws-lambda/sdk");
|
||||
|
||||
export interface StageDeps {
|
||||
loadAdapter: () => Promise<Partial<AdapterSdk>>;
|
||||
download: (url: string, dest: string, options: { maxBytes: number }) => Promise<void>;
|
||||
cacheDir: string;
|
||||
log: (line: string) => void;
|
||||
}
|
||||
|
||||
const defaultDeps: StageDeps = {
|
||||
loadAdapter: () => import("@hyperframes/aws-lambda/sdk"),
|
||||
download: downloadFile,
|
||||
cacheDir: HANDLER_CACHE_DIR,
|
||||
log: (line) => console.log(line),
|
||||
};
|
||||
|
||||
/** The one message for "no checkout and no pinned handler": everything the user needs to fix it. */
|
||||
export function noHandlerMessage(adapterInstalled: boolean): string {
|
||||
const adapter = adapterInstalled
|
||||
? " - The installed @hyperframes/aws-lambda has no prebuilt handler for its version. Install one that does:\n"
|
||||
: " - Install the Lambda adapter; its release pins the prebuilt handler:\n";
|
||||
return (
|
||||
"[lambda deploy] This is not a HyperFrames checkout, and no prebuilt Lambda handler is available.\n" +
|
||||
adapter +
|
||||
` npm install -g @hyperframes/aws-lambda@${VERSION}\n` +
|
||||
" - Or run from a hyperframes checkout, or set HYPERFRAMES_REPO_ROOT to one.\n" +
|
||||
`Docs: ${DOCS_URL}`
|
||||
);
|
||||
}
|
||||
|
||||
function sha256File(path: string): string {
|
||||
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
||||
}
|
||||
|
||||
/** Returns the directory holding the verified `handler.zip` and its `template.yaml`. */
|
||||
export async function stagePrebuiltHandler(deps: StageDeps = defaultDeps): Promise<string> {
|
||||
let sdk: Partial<AdapterSdk>;
|
||||
try {
|
||||
sdk = await deps.loadAdapter();
|
||||
} catch (err) {
|
||||
if (isMissingPackageError(err, "@hyperframes/aws-lambda"))
|
||||
throw new Error(noHandlerMessage(false));
|
||||
throw err;
|
||||
}
|
||||
// Adapters released before handler zips were published lack prebuiltHandler.
|
||||
const pinned = sdk.prebuiltHandler?.();
|
||||
if (!pinned) throw new Error(noHandlerMessage(true));
|
||||
|
||||
const dir = join(deps.cacheDir, `${pinned.version}-${pinned.sha256}`);
|
||||
const zip = join(dir, "handler.zip");
|
||||
if (existsSync(zip) && sha256File(zip) === pinned.sha256) {
|
||||
deps.log(`→ Using verified handler ZIP ${pinned.version} from ${dir}`);
|
||||
} else {
|
||||
// Override for mirrors and pre-release testing; the pinned sha256 still decides.
|
||||
const url = process.env.HYPERFRAMES_LAMBDA_HANDLER_URL ?? pinned.url;
|
||||
deps.log(`→ Downloading handler ZIP ${pinned.version} (${pinned.bytes} bytes)`);
|
||||
mkdirSync(dir, { recursive: true });
|
||||
const partial = `${zip}.download`;
|
||||
await deps.download(url, partial, { maxBytes: pinned.bytes });
|
||||
const actual = sha256File(partial);
|
||||
if (actual !== pinned.sha256) {
|
||||
unlinkSync(partial);
|
||||
const urlWithoutCredentials = url.split("?")[0];
|
||||
throw new Error(
|
||||
`[lambda deploy] Refusing the handler ZIP from ${urlWithoutCredentials}: sha256 ${actual} does not match ` +
|
||||
`the ${pinned.sha256} pinned by @hyperframes/aws-lambda@${pinned.version}.`,
|
||||
);
|
||||
}
|
||||
renameSync(partial, zip);
|
||||
deps.log(`→ Verified sha256 ${pinned.sha256}`);
|
||||
}
|
||||
copyFileSync(pinned.templatePath, join(dir, "template.yaml"));
|
||||
return dir;
|
||||
}
|
||||
@@ -4,15 +4,15 @@
|
||||
* script.
|
||||
*
|
||||
* Walks up from this file's location until it finds a directory that
|
||||
* contains `packages/aws-lambda/`. Caching is unnecessary — this runs
|
||||
* once per CLI invocation.
|
||||
* contains `packages/aws-lambda/`. Undefined outside a checkout (the
|
||||
* published CLI), where deploy uses the adapter's prebuilt handler.
|
||||
*/
|
||||
|
||||
import { existsSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
export function repoRoot(): string {
|
||||
export function repoRoot(): string | undefined {
|
||||
const override = process.env.HYPERFRAMES_REPO_ROOT;
|
||||
if (override) {
|
||||
if (existsSync(resolve(override, "packages", "aws-lambda", "package.json"))) return override;
|
||||
@@ -30,8 +30,5 @@ export function repoRoot(): string {
|
||||
if (parent === dir) break;
|
||||
dir = parent;
|
||||
}
|
||||
throw new Error(
|
||||
"[hyperframes lambda] could not find the repo root (no packages/aws-lambda/ above this CLI's source). " +
|
||||
"Run `hyperframes lambda` from within a hyperframes checkout, or set HYPERFRAMES_REPO_ROOT explicitly.",
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ describe("samDeploy", () => {
|
||||
|
||||
// An omitted override makes SAM send UsePreviousValue, so a redeploy keeps an existing cap.
|
||||
it("sends no ReservedConcurrency when --concurrency is omitted", () => {
|
||||
samDeploy({ repoRoot: "/repo", stackName: "s", region: "us-east-2" });
|
||||
samDeploy({ samDir: "/repo", stackName: "s", region: "us-east-2" });
|
||||
expect(overrides()).not.toContain("ReservedConcurrency");
|
||||
});
|
||||
|
||||
it("forwards an explicit --concurrency", () => {
|
||||
samDeploy({ repoRoot: "/repo", stackName: "s", region: "us-east-2", reservedConcurrency: 8 });
|
||||
samDeploy({ samDir: "/repo", stackName: "s", region: "us-east-2", reservedConcurrency: 8 });
|
||||
expect(overrides()).toContain("ReservedConcurrency=8");
|
||||
});
|
||||
});
|
||||
@@ -84,7 +84,7 @@ describe("parseReservedConcurrency", () => {
|
||||
for (const bad of ["abc", "0", "-1", "2.5"]) {
|
||||
expect(() => parseReservedConcurrency(bad)).toThrow('positive integer or "none"');
|
||||
}
|
||||
samDeploy({ repoRoot: "/repo", stackName: "s", region: "r", reservedConcurrency: -1 });
|
||||
samDeploy({ samDir: "/repo", stackName: "s", region: "r", reservedConcurrency: -1 });
|
||||
expect(vi.mocked(spawnSync).mock.lastCall?.[1]).toContain("ReservedConcurrency=-1");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -45,8 +45,8 @@ function assertAwsCliAvailable(): void {
|
||||
}
|
||||
|
||||
export interface DeployOptions {
|
||||
/** Repository root — the SAM template lives at `examples/aws-lambda/template.yaml` underneath. */
|
||||
repoRoot: string;
|
||||
/** Directory holding the `template.yaml` to deploy; SAM runs from here. */
|
||||
samDir: string;
|
||||
/** CloudFormation stack name. */
|
||||
stackName: string;
|
||||
region: string;
|
||||
@@ -60,8 +60,8 @@ export interface DeployOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the SAM template path relative to `repoRoot`. No installed-package fallback: the
|
||||
* template's `CodeUri` is relative to the monorepo, so it only works inside a checkout.
|
||||
* Resolve the checkout's SAM template. Its `CodeUri` is relative to the monorepo; outside a
|
||||
* checkout deploy uses the adapter's packaged template instead (see prebuiltHandler.ts).
|
||||
*/
|
||||
export function locateSamTemplate(repoRoot: string): string {
|
||||
const candidate = join(repoRoot, "examples", "aws-lambda", "template.yaml");
|
||||
@@ -116,8 +116,7 @@ export function samDeploy(opts: DeployOptions): void {
|
||||
if (opts.awsProfile) {
|
||||
args.push("--profile", opts.awsProfile);
|
||||
}
|
||||
const samDir = join(opts.repoRoot, "examples", "aws-lambda");
|
||||
const result = spawnSync("sam", args, { cwd: samDir, stdio: opts.stdio ?? "inherit" });
|
||||
const result = spawnSync("sam", args, { cwd: opts.samDir, stdio: opts.stdio ?? "inherit" });
|
||||
if (result.status !== 0) {
|
||||
throw new Error(
|
||||
`[lambda] sam deploy exited with code ${result.status ?? "unknown"}\n` +
|
||||
@@ -132,7 +131,7 @@ export function samDeploy(opts: DeployOptions): void {
|
||||
|
||||
/** Run `sam delete` non-interactively. */
|
||||
export function samDelete(opts: {
|
||||
repoRoot: string;
|
||||
samDir: string;
|
||||
stackName: string;
|
||||
region: string;
|
||||
awsProfile?: string;
|
||||
@@ -143,8 +142,7 @@ export function samDelete(opts: {
|
||||
if (opts.awsProfile) {
|
||||
args.push("--profile", opts.awsProfile);
|
||||
}
|
||||
const samDir = join(opts.repoRoot, "examples", "aws-lambda");
|
||||
const result = spawnSync("sam", args, { cwd: samDir, stdio: opts.stdio ?? "inherit" });
|
||||
const result = spawnSync("sam", args, { cwd: opts.samDir, stdio: opts.stdio ?? "inherit" });
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`[lambda] sam delete exited with code ${result.status ?? "unknown"}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user