Menu
AWS Batch
API Reference (API Version 2016-08-10)

CreateComputeEnvironment

Creates an AWS Batch compute environment. You can create MANAGED or UNMANAGED compute environments.

In a managed compute environment, AWS Batch manages the compute resources within the environment, based on the compute resources that you specify. Instances launched into a managed compute environment use a recent, approved version of the Amazon ECS-optimized AMI. You can choose to use Amazon EC2 On-Demand Instances in your managed compute environment, or you can use Amazon EC2 Spot Instances that only launch when the Spot bid price is below a specified percentage of the On-Demand price.

In an unmanaged compute environment, you can manage your own compute resources. This provides more compute resource configuration options, such as using a custom AMI, but you must ensure that your AMI meets the Amazon ECS container instance AMI specification. For more information, see Container Instance AMIs in the Amazon Elastic Container Service Developer Guide. After you have created your unmanaged compute environment, you can use the DescribeComputeEnvironments operation to find the Amazon ECS cluster that is associated with it and then manually launch your container instances into that Amazon ECS cluster. For more information, see Launching an Amazon ECS Container Instance in the Amazon Elastic Container Service Developer Guide.

Request Syntax

POST /v1/createcomputeenvironment HTTP/1.1
Content-type: application/json

{
   "computeEnvironmentName": "string",
   "computeResources": { 
      "bidPercentage": number,
      "desiredvCpus": number,
      "ec2KeyPair": "string",
      "imageId": "string",
      "instanceRole": "string",
      "instanceTypes": [ "string" ],
      "maxvCpus": number,
      "minvCpus": number,
      "securityGroupIds": [ "string" ],
      "spotIamFleetRole": "string",
      "subnets": [ "string" ],
      "tags": { 
         "string" : "string" 
      },
      "type": "string"
   },
   "serviceRole": "string",
   "state": "string",
   "type": "string"
}

URI Request Parameters

The request does not use any URI parameters.

Request Body

The request accepts the following data in JSON format.

computeEnvironmentName

The name for your compute environment. Up to 128 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed.

Type: String

Required: Yes

computeResources

Details of the compute resources managed by the compute environment. This parameter is required for managed compute environments.

Type: ComputeResource object

Required: No

serviceRole

The full Amazon Resource Name (ARN) of the IAM role that allows AWS Batch to make calls to other AWS services on your behalf.

If your specified role has a path other than /, then you must either specify the full role ARN (this is recommended) or prefix the role name with the path.

Note

Depending on how you created your AWS Batch service role, its ARN may contain the service-role path prefix. When you only specify the name of the service role, AWS Batch assumes that your ARN does not use the service-role path prefix. Because of this, we recommend that you specify the full ARN of your service role when you create compute environments.

Type: String

Required: Yes

state

The state of the compute environment. If the state is ENABLED, then the compute environment accepts jobs from a queue and can scale out automatically based on queues.

Type: String

Valid Values: ENABLED | DISABLED

Required: No

type

The type of the compute environment.

Type: String

Valid Values: MANAGED | UNMANAGED

Required: Yes

Response Syntax

HTTP/1.1 200
Content-type: application/json

{
   "computeEnvironmentArn": "string",
   "computeEnvironmentName": "string"
}

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

computeEnvironmentArn

The Amazon Resource Name (ARN) of the compute environment.

Type: String

computeEnvironmentName

The name of the compute environment.

Type: String

Errors

ClientException

These errors are usually caused by a client action, such as using an action or resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying an identifier that is not valid.

HTTP Status Code: 400

ServerException

These errors are usually caused by a server issue.

HTTP Status Code: 500

Examples

In the following example or examples, the Authorization header contents (AUTHPARAMS) must be replaced with an AWS Signature Version 4 signature. For more information about creating these signatures, see Signature Version 4 Signing Process in the AWS General Reference.

You only need to learn how to sign HTTP requests if you intend to manually create them. When you use the AWS Command Line Interface (AWS CLI) or one of the AWS SDKs to make requests to AWS, these tools automatically sign the requests for you with the access key that you specify when you configure the tools. When you use these tools, you don't need to learn how to sign requests yourself.

Example

This example creates a managed compute environment with specific C4 instance types that are launched on demand. The compute environment is called C4OnDemand.

Sample Request

POST /v1/createcomputeenvironment HTTP/1.1
Host: batch.us-east-1.amazonaws.com
Accept-Encoding: identity
Content-Length: 538
Authorization: AUTHPARAMS
X-Amz-Date: 20161128T223128Z
User-Agent: aws-cli/1.11.21 Python/2.7.12 Darwin/16.1.0 botocore/1.4.78

{
  "computeEnvironmentName": "C4OnDemand",
  "state": "ENABLED",
  "type": "MANAGED",
  "computeResources": {
    "subnets": [
      "subnet-220c0e0a",
      "subnet-1a95556d",
      "subnet-978f6dce"
    ],
    "tags": {
      "Name": "Batch Instance - C4OnDemand"
    },
    "desiredvCpus": 48,
    "minvCpus": 0,
    "instanceTypes": [
      "c4.large",
      "c4.xlarge",
      "c4.2xlarge",
      "c4.4xlarge",
      "c4.8xlarge"
    ],
    "securityGroupIds": [
      "sg-cf5093b2"
    ],
    "instanceRole": "ecsInstanceRole",
    "maxvCpus": 128,
    "type": "EC2",
    "ec2KeyPair": "id_rsa"
  },
  "serviceRole": "arn:aws:iam::012345678910:role/AWSBatchServiceRole"
}

Sample Response

HTTP/1.1 200 OK
Date: Mon, 28 Nov 2016 22:31:28 GMT
Content-Type: application/json
Content-Length: 133
Connection: keep-alive
x-amzn-RequestId: 67558123-b5ba-11e6-b909-370261104d69
X-Amzn-Trace-Id: Root=1-583cb040-93d52243313314b33c0c1e97
X-Cache: Miss from cloudfront
Via: 1.1 7e587c722adb25336835ccb4e5814e4e.cloudfront.net (CloudFront)
X-Amz-Cf-Id: GwQRsxvmiuj1HYwbYq9MAEsQfJpN6BknGQlNX1jAd5qLQFXyHBwOUQ==

{
	"computeEnvironmentName": "C4OnDemand",
	"computeEnvironmentArn": "arn:aws:batch:us-east-1:012345678910:compute-environment/C4OnDemand"
}

Example

This example creates a managed compute environment with the M4 instance type that is launched when the Spot bid price is at or below 20% of the On-Demand price for the instance type. The compute environment is called M4Spot.

Sample Request

POST /v1/createcomputeenvironment HTTP/1.1
Host: batch.us-east-1.amazonaws.com
Accept-Encoding: identity
Content-Length: 568
Authorization: AUTHPARAMS
X-Amz-Date: 20161128T223813Z
User-Agent: aws-cli/1.11.21 Python/2.7.12 Darwin/16.1.0 botocore/1.4.78

{
  "computeEnvironmentName": "M4Spot",
  "state": "ENABLED",
  "type": "MANAGED",
  "computeResources": {
    "subnets": [
      "subnet-220c0e0a",
      "subnet-1a95556d",
      "subnet-978f6dce"
    ],
    "type": "SPOT",
    "spotIamFleetRole": "arn:aws:iam::012345678910:role/aws-ec2-spot-fleet-role",
    "tags": {
      "Name": "Batch Instance - M4Spot"
    },
    "desiredvCpus": 4,
    "minvCpus": 0,
    "instanceTypes": [
      "m4"
    ],
    "securityGroupIds": [
      "sg-cf5093b2"
    ],
    "instanceRole": "ecsInstanceRole",
    "maxvCpus": 128,
    "bidPercentage": 20,
    "ec2KeyPair": "id_rsa"
  },
  "serviceRole": "arn:aws:iam::012345678910:role/AWSBatchServiceRole"
}

Sample Response

HTTP/1.1 200 OK
Date: Mon, 28 Nov 2016 22:38:16 GMT
Content-Type: application/json
Content-Length: 125
Connection: keep-alive
x-amzn-RequestId: 59422e20-b5bb-11e6-9a64-53057c7adce9
X-Amzn-Trace-Id: Root=1-583cb1d6-b71bcabf4f10bae0f3ade63b
X-Cache: Miss from cloudfront
Via: 1.1 8455edd9286a1292a39c993fdeccce65.cloudfront.net (CloudFront)
X-Amz-Cf-Id: 4mklLyUpygUko86fMNzPgA8_D64lSwPmG6iIKhAZkGpOp2e-3cKg_w==

{
	"computeEnvironmentName": "M4Spot",
	"computeEnvironmentArn": "arn:aws:batch:us-east-1:012345678910:compute-environment/M4Spot"
}

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: