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
{ "Type" : "AWS::Batch::ComputeEnvironment", "Properties" : { "Type" :String, "ServiceRole" :String, "ComputeEnvironmentName" :String, "ComputeResources" : ComputeResources, "State" :String} }
YAML
Type: AWS::Batch::ComputeEnvironment Properties: Type:StringServiceRole:StringComputeEnvironmentName:StringComputeResources: 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
ENABLEDorDISABLED. AnENABLEDstate 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
{ "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
ComputeEnvironment: Type: AWS::Batch::ComputeEnvironment Properties: Type:MANAGEDServiceRole:arn:aws:iam::111122223333:role/service-role/AWSBatchServiceRoleComputeEnvironmentName:C4OnDemandComputeResources: MaxvCpus:128SecurityGroupIds: -sg-abcd1234Type:EC2Subnets: -subnet-aaaaaaaa-subnet-bbbbbbbb-subnet-ccccccccMinvCpus:0ImageId:ami-a1b2c3d4InstanceRole:ecsInstanceRoleInstanceTypes: -c4.large-c4.xlarge-c4.2xlarge-c4.4xlarge-c4.8xlargeEc2KeyPair:id_rsaTags:{"Name": "Batch Instance - C4OnDemand"}DesiredvCpus:48State:ENABLED
The following example creates a compute environment named my-first-compute-environment and specifies tags for the compute resources.
JSON
"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
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
