Skip to main content

Job

The Job construct is a higher level CDK construct that makes it easy to perform long running jobs.

Examples

Creating a Job

import { Job } from "sst/constructs";

new Job(stack, "MyJob", {
handler: "src/job.main",
});

Setting additional props

new Job(stack, "MyJob", {
handler: "job.main",
srcPath: "services",
timeout: "30 minutes",
memorySize: "3 GB",
config: [STRIPE_KEY, API_URL],
permissions: ["ses", bucket],
});

Create a job in a VPC

import { Job } from "sst/constructs";
import { Vpc } from "aws-cdk-lib/aws-ec2";

new Job(stack, "MyJob", {
handler: "src/job.main",
cdk: {
vpc: Vpc.fromLookup(stack, "VPC", {
vpcId: "vpc-xxxxxxxxxx",
}),
},
});

Constructor

new Job(scope, id, props)

Parameters

JobProps

bind?

Type : Array<SSTConstruct>

Bind resources for the job

new Job(stack, "MyJob", {
handler: "src/job.handler",
bind: [STRIPE_KEY, bucket],
})

enableLiveDev?

Type : boolean

Can be used to disable Live Lambda Development when using sst start . Useful for things like Custom Resources that need to execute during deployment.

new Job(stack, "MyJob", {
handler: "src/job.handler",
enableLiveDev: false
})

environment?

Type : Record<string, string>

Configure environment variables for the job

new Job(stack, "MyJob", {
handler: "src/job.handler",
environment: {
DEBUG: "*",
}
})

handler

Type : string

Path to the entry point and handler function. Of the format:

/path/to/file.function .

new Job(stack, "MyJob", {
handler: "src/job.handler",
})

memorySize?

Type : "3 GB" | "7 GB" | "15 GB" | "145 GB"

The amount of memory in MB allocated.

new Job(stack, "MyJob", {
handler: "src/job.handler",
memorySize: "3 GB",
})

permissions?

Type : Permissions

Attaches the given list of permissions to the job. Configuring this property is equivalent to calling attachPermissions() after the job is created.

new Job(stack, "MyJob", {
handler: "src/job.handler",
permissions: ["ses"]
})

timeout?

Type : ${number} second | ${number} seconds | ${number} minute | ${number} minutes | ${number} hour | ${number} hours | ${number} day | ${number} days

The execution timeout. Minimum 5 minutes. Maximum 8 hours.

new Job(stack, "MyJob", {
handler: "src/job.handler",
timeout: "30 minutes",
})

cdk.id?

Type : string

Allows you to override default id for this construct.

cdk.vpc?

Type : IVpc

Runs codebuild job in the specified VPC. Note this will only work once deployed.

new Job(stack, "MyJob", {
handler: "src/job.handler",
cdk: {
vpc: Vpc.fromLookup(stack, "VPC", {
vpcId: "vpc-xxxxxxxxxx",
}),
}
})

Properties

An instance of Job has the following properties.

id

Type : string

Methods

An instance of Job has the following methods.

addEnvironment

addEnvironment(name, value)

Parameters

  • name string
  • value string

Attaches additional environment variable to the job.

fn.addEnvironment({
DEBUG: "*"
});

attachPermissions

attachPermissions(permissions)

Parameters

Attaches the given list of permissions to the job. This allows the job to access other AWS resources.

job.attachPermissions(["ses"]);

bind

bind(constructs)

Parameters

  • constructs Array<SSTConstruct>

Binds additional resources to job.

job.bind([STRIPE_KEY, bucket]);