import { Construct } from "constructs"; import { DockerCacheOption } from "aws-cdk-lib/core"; import { Function as CdkFunction } from "aws-cdk-lib/aws-lambda"; import { Project } from "aws-cdk-lib/aws-codebuild"; import { RetentionDays } from "aws-cdk-lib/aws-logs"; import { SSTConstruct } from "./Construct.js"; import { NodeJSProps, FunctionCopyFilesProps } from "./Function.js"; import { Duration } from "./util/duration.js"; import { Permissions } from "./util/permission.js"; import { BindingResource, BindingProps } from "./util/binding.js"; import { ISecurityGroup, IVpc, SubnetSelection } from "aws-cdk-lib/aws-ec2"; export type JobMemorySize = "3 GB" | "7 GB" | "15 GB" | "145 GB"; export interface JobNodeJSProps extends NodeJSProps { } export interface JobContainerCacheProps extends DockerCacheOption { } export interface JobContainerProps { /** * Specify or override the CMD on the Docker image. * @example * ```js * container: { * cmd: ["python3", "my_script.py"] * } * ``` */ cmd: string[]; /** * Name of the Dockerfile. * @example * ```js * container: { * file: "path/to/Dockerfile.prod" * } * ``` */ file?: string; /** * Build args to pass to the docker build command. * @default No build args * @example * ```js * container: { * buildArgs: { * FOO: "bar" * } * } * ``` */ buildArgs?: Record; /** * SSH agent socket or keys to pass to the docker build command. * Docker BuildKit must be enabled to use the ssh flag * @default No --ssh flag is passed to the build command * @example * ```js * container: { * buildSsh: "default" * } * ``` */ buildSsh?: string; /** * Cache from options to pass to the docker build command. * [DockerCacheOption](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerCacheOption.html)[]. * @default No cache from options are passed to the build command * @example * ```js * container: { * cacheFrom: [{ type: 'registry', params: { ref: 'ghcr.io/myorg/myimage:cache' }}], * } * ``` */ cacheFrom?: JobContainerCacheProps[]; /** * Cache to options to pass to the docker build command. * [DockerCacheOption](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerCacheOption.html)[]. * @default No cache to options are passed to the build command * @example * ```js * container: { * cacheTo: { type: 'registry', params: { ref: 'ghcr.io/myorg/myimage:cache', mode: 'max', compression: 'zstd' }}, * } * ``` */ cacheTo?: JobContainerCacheProps; } export interface JobProps { /** * The CPU architecture of the job. * @default "x86_64" * @example * ```js * new Job(stack, "MyJob", { * architecture: "arm_64", * handler: "src/job.handler", * }) * ``` */ architecture?: "x86_64" | "arm_64"; /** * The runtime environment for the job. * @default "nodejs18.x" * @example * ```js * new Job(stack, "MyJob", { * runtime: "container", * handler: "src/job", * }) *``` */ runtime?: "nodejs" | "nodejs16.x" | "nodejs18.x" | "nodejs20.x" | "nodejs22.x" | "container"; /** * For "nodejs" runtime, point to the entry point and handler function. * Of the format: `/path/to/file.function`. * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * }) *``` * * For "container" runtime, point the handler to the directory containing * the Dockerfile. * * @example * ```js * new Job(stack, "MyJob", { * runtime: "container", * handler: "src/job", // Dockerfile is at "src/job/Dockerfile" * }) *``` */ handler: string; /** * The amount of memory in MB allocated. * * @default "3 GB" * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * memorySize: "3 GB", * }) *``` */ memorySize?: JobMemorySize; /** * The execution timeout. Minimum 5 minutes. Maximum 36 hours. * * @default "8 hours" * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * timeout: "30 minutes", * }) *``` */ timeout?: Duration; /** * Used to configure additional files to copy into the function bundle * * @example * ```js * new Job(stack, "job", { * copyFiles: [{ from: "src/index.js" }] * }) *``` */ copyFiles?: FunctionCopyFilesProps[]; /** * Used to configure nodejs function properties */ nodejs?: JobNodeJSProps; /** * Used to configure container properties */ container?: JobContainerProps; /** * Can be used to disable Live Lambda Development when using `sst start`. Useful for things like Custom Resources that need to execute during deployment. * * @default true * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * enableLiveDev: false * }) *``` */ enableLiveDev?: boolean; /** * Configure environment variables for the job * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * environment: { * DEBUG: "*", * } * }) * ``` */ environment?: Record; /** * Bind resources for the job * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * bind: [STRIPE_KEY, bucket], * }) * ``` */ bind?: BindingResource[]; /** * Attaches the given list of permissions to the job. Configuring this property is equivalent to calling `attachPermissions()` after the job is created. * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * permissions: ["ses"] * }) * ``` */ permissions?: Permissions; /** * The duration logs are kept in CloudWatch Logs. * @default Logs retained indefinitely * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * logRetention: "one_week" * }) * ``` */ logRetention?: Lowercase; cdk?: { /** * Allows you to override default id for this construct. */ id?: string; /** * Runs codebuild job in the specified VPC. Note this will only work once deployed. * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * cdk: { * vpc: Vpc.fromLookup(stack, "VPC", { * vpcId: "vpc-xxxxxxxxxx", * }), * } * }) * ``` */ vpc?: IVpc; /** * Where to place the network interfaces within the VPC. * @default All private subnets. * @example * ```js * import { SubnetType } from "aws-cdk-lib/aws-ec2"; * * new Job(stack, "MyJob", { * handler: "src/job.handler", * cdk: { * vpc, * vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS } * } * }) * ``` */ vpcSubnets?: SubnetSelection; /** * The list of security groups to associate with the Job's network interfaces. * @default A new security group is created. * @example * ```js * import { SecurityGroup } from "aws-cdk-lib/aws-ec2"; * * new Job(stack, "MyJob", { * handler: "src/job.handler", * cdk: { * vpc, * securityGroups: [ * new SecurityGroup(stack, "MyJobSG", { vpc }) * ] * } * }) * ``` */ securityGroups?: ISecurityGroup[]; }; } /** * The `Cron` construct is a higher level CDK construct that makes it easy to create a cron job. * * @example * * ```js * import { Cron } from "sst/constructs"; * * new Cron(stack, "Cron", { * schedule: "rate(1 minute)", * job: "src/lambda.main", * }); * ``` */ export declare class Job extends Construct implements SSTConstruct { readonly id: string; private readonly props; private readonly job; private readonly liveDevJob?; readonly _jobManager: CdkFunction; constructor(scope: Construct, id: string, props: JobProps); getConstructMetadata(): { type: "Job"; data: { handler: string; }; }; /** @internal */ getBindings(): BindingProps; /** * Binds additional resources to job. * * @example * ```js * job.bind([STRIPE_KEY, bucket]); * ``` */ bind(constructs: BindingResource[]): void; /** * Attaches the given list of [permissions](Permissions.md) to the job. This allows the job to access other AWS resources. * * @example * ```js * job.attachPermissions(["ses"]); * ``` */ attachPermissions(permissions: Permissions): void; /** * Attaches additional environment variable to the job. * * @example * ```js * fn.addEnvironment({ * DEBUG: "*" * }); * ``` */ addEnvironment(name: string, value: string): void; get cdk(): { codeBuildProject: Project; }; private createCodeBuildJob; private createLiveDevJob; private createLogRetention; private buildCodeBuildProjectCode; private createJobManager; private bindForCodeBuild; private attachPermissionsForCodeBuild; private addEnvironmentForCodeBuild; private validateContainerProps; private validateMemoryProps; private normalizeMemorySize; private normalizeTimeout; private convertJobRuntimeToFunctionRuntime; }