import { Construct } from "constructs"; import { Secret, Parameter } from "./Config.js"; import { SSTConstruct } from "./Construct.js"; import { Function } from "./Function.js"; import { Duration } from "./util/duration.js"; import { Permissions } from "./util/permission.js"; import { IVpc } from "aws-cdk-lib/aws-ec2"; export declare type JobMemorySize = "3 GB" | "7 GB" | "15 GB" | "145 GB"; export interface JobProps { /** * Path to the entry point and handler function. Of the format: * `/path/to/file.function`. * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * }) *``` */ handler: string; /** * Root directory of the project, typically where package.json is located. Set if using a monorepo with multiple subpackages * * @default Defaults to the same directory as sst.json * * @example * ```js * new Job(stack, "MyJob", { * srcPath: "services", * handler: "job.handler", * }) *``` */ srcPath?: 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 8 hours. * * @default "8 hours" * * @example * ```js * new Job(stack, "MyJob", { * handler: "src/job.handler", * timeout: "30 minutes", * }) *``` */ timeout?: Duration; /** * 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?: SSTConstruct[]; /** * Configure environment variables for the job * * @deprecated The "config" prop is deprecated, and will be removed in SST v2. Pass Parameters and Secrets in through the "bind" prop. Read more about how to upgrade here — https://docs.serverless-stack.com/constructs/function * * @example * ```js * // Change * new Job(stack, "MyJob", { * handler: "src/job.handler", * config: [STRIPE_KEY, API_URL] * }) * * // To * new Job(stack, "MyJob", { * handler: "src/job.handler", * bind: [STRIPE_KEY, API_URL] * }) * ``` */ config?: (Secret | Parameter)[]; /** * 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; cdk?: JobCDKProps; } export interface JobCDKProps { /** * 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(this, "VPC", { * vpcId: "vpc-xxxxxxxxxx", * }), * } * }) * ``` */ vpc?: IVpc; } /** * The `Cron` construct is a higher level CDK construct that makes it easy to create a cron job. * * @example * * ```js * import { Cron } from "@serverless-stack/resources"; * * 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 localId; private readonly props; private readonly job; private readonly isLiveDevEnabled; readonly _jobInvoker: Function; constructor(scope: Construct, id: string, props: JobProps); getConstructMetadata(): { type: "Job"; data: {}; }; /** @internal */ getFunctionBinding(): { clientPackage: string; variables: { functionName: { environment: string; parameter: string; }; }; permissions: { "lambda:*": string[]; }; }; /** * Binds additional resources to job. * * @example * ```js * job.bind([STRIPE_KEY, bucket]); * ``` */ bind(constructs: SSTConstruct[]): void; /** * Attaches additional configs to job. * * @deprecated The "config" prop is deprecated, and will be removed in SST v2. Pass Parameters and Secrets in through the "bind" prop. Read more about how to upgrade here — https://docs.serverless-stack.com/constructs/function * * @example * ```js * const STRIPE_KEY = new Config.Secret(stack, "STRIPE_KEY"); * * // Change * job.addConfig([STRIPE_KEY]); * * // To * job.bind([STRIPE_KEY]); * ``` */ addConfig(config: (Secret | Parameter)[]): 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; private createCodeBuildProject; private buildCodeBuildProjectCode; private updateCodeBuildProjectCode; private createLocalInvoker; private createCodeBuildInvoker; private useForCodeBuild; private attachPermissionsForCodeBuild; private addEnvironmentForCodeBuild; private normalizeMemorySize; private normalizeTimeout; }