A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
AWS Batch runs batch computing workloads on AWS.
const computeEnv = new aws.batch.ComputeEnvironment("batch-compute", {
computeEnvironmentName: "my-batch-env",
type: "MANAGED",
serviceRole: batchServiceRole.arn,
computeResources: {
type: "FARGATE",
maxVcpus: 16,
subnets: [subnet1.id, subnet2.id],
securityGroupIds: [sg.id],
},
});const jobDef = new aws.batch.JobDefinition("job", {
name: "my-job",
type: "container",
platformCapabilities: ["FARGATE"],
containerProperties: JSON.stringify({
image: "my-app:latest",
resourceRequirements: [
{ type: "VCPU", value: "0.25" },
{ type: "MEMORY", value: "512" },
],
executionRoleArn: executionRole.arn,
}),
});
const jobQueue = new aws.batch.JobQueue("queue", {
name: "my-queue",
state: "ENABLED",
priority: 1,
computeEnvironments: [{
order: 1,
computeEnvironment: computeEnv.arn,
}],
});Manages compute resources for running batch jobs.
class ComputeEnvironment extends pulumi.CustomResource {
constructor(name: string, args: ComputeEnvironmentArgs, opts?: pulumi.CustomResourceOptions);
readonly arn: pulumi.Output<string>;
}
interface ComputeEnvironmentArgs {
computeEnvironmentName?: pulumi.Input<string>;
type: pulumi.Input<"MANAGED" | "UNMANAGED">;
serviceRole?: pulumi.Input<string>;
computeResources?: pulumi.Input<ComputeResources>;
state?: pulumi.Input<"ENABLED" | "DISABLED">;
tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
}
interface ComputeResources {
type: pulumi.Input<"EC2" | "SPOT" | "FARGATE" | "FARGATE_SPOT">;
maxVcpus: pulumi.Input<number>;
minVcpus?: pulumi.Input<number>;
subnets: pulumi.Input<pulumi.Input<string>[]>;
securityGroupIds?: pulumi.Input<pulumi.Input<string>[]>;
instanceRole?: pulumi.Input<string>;
instanceTypes?: pulumi.Input<pulumi.Input<string>[]>;
}Usage Example:
const computeEnv = new aws.batch.ComputeEnvironment("batch-compute", {
computeEnvironmentName: "my-batch-env",
type: "MANAGED",
serviceRole: batchServiceRole.arn,
computeResources: {
type: "FARGATE",
maxVcpus: 16,
subnets: [subnet1.id, subnet2.id],
securityGroupIds: [sg.id],
},
state: "ENABLED",
tags: { Environment: "production" },
});Defines job parameters including container image, resources, and environment.
class JobDefinition extends pulumi.CustomResource {
constructor(name: string, args: JobDefinitionArgs, opts?: pulumi.CustomResourceOptions);
readonly arn: pulumi.Output<string>;
}
interface JobDefinitionArgs {
name: pulumi.Input<string>;
type: pulumi.Input<"container" | "multinode">;
platformCapabilities?: pulumi.Input<pulumi.Input<"EC2" | "FARGATE">[]>;
containerProperties?: pulumi.Input<string>;
retryStrategy?: pulumi.Input<RetryStrategy>;
timeout?: pulumi.Input<JobTimeout>;
tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
}
interface RetryStrategy {
attempts?: pulumi.Input<number>;
}
interface JobTimeout {
attemptDurationSeconds?: pulumi.Input<number>;
}Usage Example:
const jobDef = new aws.batch.JobDefinition("my-job", {
name: "data-processor",
type: "container",
platformCapabilities: ["FARGATE"],
containerProperties: JSON.stringify({
image: "my-app:latest",
resourceRequirements: [
{ type: "VCPU", value: "1" },
{ type: "MEMORY", value: "2048" },
],
executionRoleArn: executionRole.arn,
jobRoleArn: jobRole.arn,
environment: [
{ name: "ENV", value: "production" },
],
}),
retryStrategy: {
attempts: 3,
},
timeout: {
attemptDurationSeconds: 3600,
},
});Routes jobs to compute environments.
class JobQueue extends pulumi.CustomResource {
constructor(name: string, args: JobQueueArgs, opts?: pulumi.CustomResourceOptions);
readonly arn: pulumi.Output<string>;
}
interface JobQueueArgs {
name: pulumi.Input<string>;
state: pulumi.Input<"ENABLED" | "DISABLED">;
priority: pulumi.Input<number>;
computeEnvironments: pulumi.Input<pulumi.Input<JobQueueComputeEnvironment>[]>;
tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
}
interface JobQueueComputeEnvironment {
order: pulumi.Input<number>;
computeEnvironment: pulumi.Input<string>;
}Usage Example:
const jobQueue = new aws.batch.JobQueue("my-queue", {
name: "high-priority-queue",
state: "ENABLED",
priority: 10,
computeEnvironments: [
{
order: 1,
computeEnvironment: computeEnv1.arn,
},
{
order: 2,
computeEnvironment: computeEnv2.arn,
},
],
tags: { Environment: "production" },
});Defines fair share scheduling policies for job queues.
class SchedulingPolicy extends pulumi.CustomResource {
constructor(name: string, args: SchedulingPolicyArgs, opts?: pulumi.CustomResourceOptions);
readonly arn: pulumi.Output<string>;
}
interface SchedulingPolicyArgs {
name: pulumi.Input<string>;
fairsharePolicy?: pulumi.Input<FairsharePolicy>;
tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
}
interface FairsharePolicy {
shareDecaySeconds?: pulumi.Input<number>;
computeReservation?: pulumi.Input<number>;
shareDistribution?: pulumi.Input<pulumi.Input<ShareAttributes>[]>;
}
interface ShareAttributes {
shareIdentifier: pulumi.Input<string>;
weightFactor?: pulumi.Input<number>;
}Usage Example:
const schedulingPolicy = new aws.batch.SchedulingPolicy("fair-share", {
name: "my-scheduling-policy",
fairsharePolicy: {
shareDecaySeconds: 3600,
computeReservation: 1,
shareDistribution: [
{ shareIdentifier: "TeamA", weightFactor: 0.5 },
{ shareIdentifier: "TeamB", weightFactor: 0.3 },
{ shareIdentifier: "TeamC", weightFactor: 0.2 },
],
},
});import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create batch service role
const batchServiceRole = new aws.iam.Role("batch-service-role", {
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Action: "sts:AssumeRole",
Effect: "Allow",
Principal: { Service: "batch.amazonaws.com" },
}],
}),
});
new aws.iam.RolePolicyAttachment("batch-service-policy", {
role: batchServiceRole.name,
policyArn: "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole",
});
// Create compute environment
const computeEnv = new aws.batch.ComputeEnvironment("batch-compute", {
computeEnvironmentName: "my-batch-env",
type: "MANAGED",
serviceRole: batchServiceRole.arn,
computeResources: {
type: "FARGATE",
maxVcpus: 16,
subnets: [subnet1.id, subnet2.id],
securityGroupIds: [sg.id],
},
});
// Create job definition
const jobDef = new aws.batch.JobDefinition("my-job", {
name: "data-processor",
type: "container",
platformCapabilities: ["FARGATE"],
containerProperties: JSON.stringify({
image: "my-app:latest",
resourceRequirements: [
{ type: "VCPU", value: "1" },
{ type: "MEMORY", value: "2048" },
],
executionRoleArn: executionRole.arn,
}),
});
// Create job queue
const jobQueue = new aws.batch.JobQueue("my-queue", {
name: "my-queue",
state: "ENABLED",
priority: 1,
computeEnvironments: [{
order: 1,
computeEnvironment: computeEnv.arn,
}],
});
export const queueArn = jobQueue.arn;For complete Batch API with signatures and examples, see All Services.
Install with Tessl CLI
npx tessl i tessl/npm-pulumi--aws@7.16.0