mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 16:37:32 +00:00
A folder above the CLI's own package that holds packages/aws-lambda no longer counts as a checkout, and a source checkout is named before it is built or deployed from.
60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
/**
|
|
* `hyperframes lambda destroy` — tear the CloudFormation stack down and
|
|
* drop the locally-cached stack outputs. Wraps `sam delete`.
|
|
*
|
|
* The render bucket is created with `Retain` deletion policy in the SAM
|
|
* template, so the underlying S3 bucket survives destruction. Adopters
|
|
* who want to fully delete it must do so via the AWS console / CLI
|
|
* after this command completes; we document that in the deploy guide
|
|
* rather than re-implementing the empty-and-delete dance here.
|
|
*/
|
|
|
|
import { mkdtempSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { c } from "../../ui/colors.js";
|
|
import { terminalText } from "@hyperframes/core";
|
|
import { deleteStackOutputs, requireStack } from "./state.js";
|
|
import { deleteEcrRepository, samDelete } from "./sam.js";
|
|
import { repoRoot } from "./repoRoot.js";
|
|
import { videoRepositoryName } from "./videoImage.js";
|
|
|
|
export interface DestroyArgs {
|
|
stackName: string;
|
|
awsProfile?: string;
|
|
}
|
|
|
|
export async function runDestroy(args: DestroyArgs): Promise<void> {
|
|
const stack = requireStack(args.stackName);
|
|
console.log(
|
|
c.dim(terminalText(`→ sam delete (stack=${stack.stackName} region=${stack.region})`)),
|
|
);
|
|
const root = repoRoot();
|
|
if (root) console.log(c.dim(terminalText(`→ Using the source checkout at ${root}`)));
|
|
const awsProfile = args.awsProfile ?? process.env.AWS_PROFILE;
|
|
// 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.
|
|
const samDir = root
|
|
? join(root, "examples", "aws-lambda")
|
|
: mkdtempSync(join(tmpdir(), "hf-sam-"));
|
|
try {
|
|
samDelete({ samDir, stackName: stack.stackName, region: stack.region, awsProfile });
|
|
} finally {
|
|
if (!root) rmSync(samDir, { recursive: true, force: true });
|
|
}
|
|
if (stack.videoRepository) {
|
|
const repositoryName = videoRepositoryName(stack.stackName);
|
|
console.log(c.dim(terminalText(`→ Deleting ECR repository ${repositoryName}`)));
|
|
deleteEcrRepository({ repositoryName, region: stack.region, awsProfile });
|
|
}
|
|
deleteStackOutputs(args.stackName);
|
|
console.log();
|
|
console.log(c.success("Stack torn down."));
|
|
console.log(
|
|
c.dim(
|
|
`Note: the render bucket "${terminalText(stack.bucketName)}" was deployed with Retain — empty + delete it via the AWS console or CLI if you want to fully reclaim storage.`,
|
|
),
|
|
);
|
|
}
|