Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

AWS::Batch::ComputeEnvironment

The AWS::Batch::ComputeEnvironment resource to define your AWS Batch compute environment. For more information, see Compute Environments in the AWS Batch User Guide.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

Copy
{ "Type" : "AWS::Batch::ComputeEnvironment", "Properties" : { "Type" : String, "ServiceRole" : String, "ComputeEnvironmentName" : String, "ComputeResources" : ComputeResources, "State" : String } }

YAML

Copy
Type: "AWS::Batch::ComputeEnvironment" Properties: Type: String ServiceRole: String ComputeEnvironmentName: String ComputeResources: ComputeResources State: String

Properties

Type

The type of the compute environment.

Required: yes

Type: String

Update requires: Replacement

ServiceRole

The service role associated with the compute environment that allows AWS Batch to make calls to AWS API operations on your behalf.

Required: yes

Type: String

Update requires: No Interruption

ComputeEnvironmentName

The name of the compute environment.

Required: no

Type: String

Update requires: Replacement

ComputeResources

The compute resources defined for the compute environment.

Required: yes

Type: AWS Batch ComputeEnvironment ComputeResources

Update requires: No Interruption

State

The state of the compute environment. The valid values are ENABLED or DISABLED. An ENABLED state indicates that you can register instances with the compute environment and that the associated instances can accept jobs.

Required: no

Type: String

Update requires: No Interruption

Return Values

Ref

When you pass the logical ID of an AWS::Batch::ComputeEnvironment resource to the intrinsic Ref function, the function returns the compute environment ARN, such as arn:aws:batch:us-east-1:555555555555:compute-environment/M4OnDemand.

For more information about using the Ref function, see Ref.

Examples

Managed Compute Environment

The following example creates a managed compute environment called C4OnDemand that uses C4 On-Demand instances and a custom AMI.

JSON

Copy
{ "ComputeEnvironment": { "Type": "AWS::Batch::ComputeEnvironment", "Properties": { "Type": "MANAGED", "ServiceRole": "arn:aws:iam::111122223333:role/service-role/AWSBatchServiceRole", "ComputeEnvironmentName": "C4OnDemand", "ComputeResources": { "MaxvCpus": 128, "SecurityGroupIds": [ "sg-abcd1234" ], "Type": "EC2", "Subnets": [ "subnet-aaaaaaaa", "subnet-bbbbbbbb", "subnet-cccccccc" ], "MinvCpus": 0, "ImageId": "ami-a1b2c3d4", "InstanceRole": "ecsInstanceRole", "InstanceTypes": [ "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge" ], "Ec2KeyPair": "id_rsa", "Tags": {"Name": "Batch Instance - C4OnDemand"}, "DesiredvCpus": 48 }, "State": "ENABLED" } } }

YAML

Copy
ComputeEnvironment: Type: AWS::Batch::ComputeEnvironment Properties: Type: MANAGED ServiceRole: arn:aws:iam::111122223333:role/service-role/AWSBatchServiceRole ComputeEnvironmentName: C4OnDemand ComputeResources: MaxvCpus: 128 SecurityGroupIds: - sg-abcd1234 Type: EC2 Subnets: - subnet-aaaaaaaa - subnet-bbbbbbbb - subnet-cccccccc MinvCpus: 0 ImageId: ami-a1b2c3d4 InstanceRole: ecsInstanceRole InstanceTypes: - c4.large - c4.xlarge - c4.2xlarge - c4.4xlarge - c4.8xlarge Ec2KeyPair: id_rsa Tags: {"Name": "Batch Instance - C4OnDemand"} DesiredvCpus: 48 State: ENABLED

The following example creates a compute environment named my-first-compute-environment and specifies tags for the compute resources.

JSON

Copy
"MyComputeEnv": { "Type": "AWS::Batch::ComputeEnvironment", "Properties": { "Type": "MANAGED", "ServiceRole": "AWSBatchServiceRole", "ComputeEnvironmentName": "my-first-compute-environment", "ComputeResources": { "MinvCpus": "4", "MaxvCpus": "256", "DesiredvCpus": "4", "SecurityGroupIds": [ "sg-a1b2c3d4", "sg-4d3c2ba1" ], "Type": "EC2", "Subnets": [ "subnet-12345678", "subnet-87654321" ], "InstanceRole": "batch-instance-profile", "InstanceTypes": [ "optimal" ], "Ec2KeyPair": { "Ref": "MyKeyPair" }, "Tags": { "Owner": "A", "Project": "B" } }, "State": "ENABLED" } }

YAML

Copy
MyComputeEnv: Type: AWS::Batch::ComputeEnvironment Properties: Type: MANAGED ServiceRole: AWSBatchServiceRole ComputeEnvironmentName: my-first-compute-environment ComputeResources: MinvCpus: 4 MaxvCpus: 256 DesiredvCpus: 4 SecurityGroupIds: - sg-a1b2c3d4 - sg-4d3c2ba1 Type: EC2 Subnets: - subnet-12345678 - subnet-87654321 InstanceRole: batch-instance-profile InstanceTypes: - optimal Ec2KeyPair: !Ref MyKeyPair Tags: Owner: A Project: B State: ENABLED