Skip to content

Resource: awsBatchJobDefinition

Provides a Batch Job Definition resource.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.batchJobDefinition.BatchJobDefinition(this, "test", {
  containerProperties:
    '${jsonencode({\n    command = ["ls", "-la"],\n    image   = "busybox"\n\n    resourceRequirements = [\n      {\n        type  = "VCPU"\n        value = "0.25"\n      },\n      {\n        type  = "MEMORY"\n        value = "512"\n      }\n    ]\n\n    volumes = [\n      {\n        host = {\n          sourcePath = "/tmp"\n        }\n        name = "tmp"\n      }\n    ]\n\n    environment = [\n      {\n        name  = "VARNAME"\n        value = "VARVAL"\n      }\n    ]\n\n    mountPoints = [\n      {\n        sourceVolume  = "tmp"\n        containerPath = "/tmp"\n        readOnly      = false\n      }\n    ]\n\n    ulimits = [\n      {\n        hardLimit = 1024\n        name      = "nofile"\n        softLimit = 1024\n      }\n    ]\n  })}',
  name: "tf_test_batch_job_definition",
  type: "container",
});

Fargate Platform Capability

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.batchJobDefinition.BatchJobDefinition(this, "test", {
  containerProperties:
    '${jsonencode({\n    command    = ["echo", "test"]\n    image      = "busybox"\n    jobRoleArn = "arn:aws:iam::123456789012:role/AWSBatchS3ReadOnly"\n\n    fargatePlatformConfiguration = {\n      platformVersion = "LATEST"\n    }\n\n    resourceRequirements = [\n      {\n        type  = "VCPU"\n        value = "0.25"\n      },\n      {\n        type  = "MEMORY"\n        value = "512"\n      }\n    ]\n\n    executionRoleArn = aws_iam_role.ecs_task_execution_role.arn\n  })}',
  name: "tf_test_batch_job_definition",
  platformCapabilities: ["FARGATE"],
  type: "container",
});
const dataAwsIamPolicyDocumentAssumeRolePolicy =
  new aws.dataAwsIamPolicyDocument.DataAwsIamPolicyDocument(
    this,
    "assume_role_policy",
    {
      statement: [
        {
          actions: ["sts:AssumeRole"],
          principals: [
            {
              identifiers: ["ecs-tasks.amazonaws.com"],
              type: "Service",
            },
          ],
        },
      ],
    }
  );
const awsIamRoleEcsTaskExecutionRole = new aws.iamRole.IamRole(
  this,
  "ecs_task_execution_role",
  {
    assumeRolePolicy: dataAwsIamPolicyDocumentAssumeRolePolicy.json,
    name: "tf_test_batch_exec_role",
  }
);
new aws.iamRolePolicyAttachment.IamRolePolicyAttachment(
  this,
  "ecs_task_execution_role_policy",
  {
    policyArn:
      "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy",
    role: awsIamRoleEcsTaskExecutionRole.name,
  }
);

Argument Reference

The following arguments are required:

  • name - (Required) Specifies the name of the job definition.
  • type - (Required) The type of job definition. Must be container.

The following arguments are optional:

  • containerProperties - (Optional) A valid container properties provided as a single valid JSON document. This parameter is required if the type parameter is container.
  • parameters - (Optional) Specifies the parameter substitution placeholders to set in the job definition.
  • platformCapabilities - (Optional) The platform capabilities required by the job definition. If no value is specified, it defaults to ec2. To run the job on Fargate resources, specify fargate.
  • propagateTags - (Optional) Specifies whether to propagate the tags from the job definition to the corresponding Amazon ECS task. Default is false.
  • retryStrategy - (Optional) Specifies the retry strategy to use for failed jobs that are submitted with this job definition. Maximum number of retryStrategy is 1. Defined below.
  • tags - (Optional) Key-value map of resource tags. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
  • timeout - (Optional) Specifies the timeout for jobs so that if a job runs longer, AWS Batch terminates the job. Maximum number of timeout is 1. Defined below.

retryStrategy

  • attempts - (Optional) The number of times to move a job to the runnable status. You may specify between 1 and 10 attempts.
  • evaluateOnExit - (Optional) The evaluate on exit conditions under which the job should be retried or failed. If this parameter is specified, then the attempts parameter must also be specified. You may specify up to 5 configuration blocks.

evaluateOnExit

  • action - (Required) Specifies the action to take if all of the specified conditions are met. The values are not case sensitive. Valid values: retry, exit.
  • onExitCode - (Optional) A glob pattern to match against the decimal representation of the exit code returned for a job.
  • onReason - (Optional) A glob pattern to match against the reason returned for a job.
  • onStatusReason - (Optional) A glob pattern to match against the status reason returned for a job.

timeout

  • attemptDurationSeconds - (Optional) The time duration in seconds after which AWS Batch terminates your jobs if they have not finished. The minimum value for the timeout is 60 seconds.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • arn - The Amazon Resource Name of the job definition.
  • revision - The revision of the job definition.
  • tagsAll - A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

Batch Job Definition can be imported using the arn, e.g.,

$ terraform import aws_batch_job_definition.test arn:aws:batch:us-east-1:123456789012:job-definition/sample