CreateComputeEnvironment
Creates an AWS Batch compute environment. You can create MANAGED or
UNMANAGED compute environments. MANAGED compute environments can
use Amazon EC2 or AWS Fargate resources. UNMANAGED compute environments can only use
EC2 resources.
In a managed compute environment, AWS Batch manages the capacity and instance types of the compute resources within the environment. This is based on the compute resource specification that you define or the launch template that you specify when you create the compute environment. Either, you can choose to use EC2 On-Demand Instances and EC2 Spot Instances. Or, you can use Fargate and Fargate Spot capacity in your managed compute environment. You can optionally set a maximum price so that Spot Instances only launch when the Spot Instance price is less than a specified percentage of the On-Demand price.
In an unmanaged compute environment, you can manage your own EC2 compute resources and have flexibility with how you configure your compute resources. For example, you can use custom AMIs. However, you must verify that each of your AMIs meet the Amazon ECS container instance AMI specification. For more information, see container instance AMIs in the Amazon Elastic Container Service Developer Guide. After you created your unmanaged compute environment, you can use the DescribeComputeEnvironments operation to find the Amazon ECS cluster that's associated with it. Then, 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.
Note
AWS Batch doesn't automatically upgrade the AMIs in a compute environment after it's created. For more information on how to update a compute environment's AMI, see Updating compute environments in the AWS Batch User Guide.
Request Syntax
POST /v1/createcomputeenvironment HTTP/1.1
Content-type: application/json
{
"computeEnvironmentName": "string",
"computeResources": {
"allocationStrategy": "string",
"bidPercentage": number,
"capacityTags": {
"string" : "string"
},
"desiredvCpus": number,
"ec2Configuration": [
{
"batchImageStatus": "string",
"imageIdOverride": "string",
"imageKubernetesVersion": "string",
"imageType": "string"
}
],
"ec2KeyPair": "string",
"imageId": "string",
"instanceRole": "string",
"instanceTypes": [ "string" ],
"launchTemplate": {
"launchTemplateId": "string",
"launchTemplateName": "string",
"overrides": [
{
"launchTemplateId": "string",
"launchTemplateName": "string",
"targetInstanceTypes": [ "string" ],
"userdataType": "string",
"version": "string"
}
],
"userdataType": "string",
"version": "string"
},
"managedInstancesProvider": {
"infrastructureOptimization": {
"scaleInAfter": number
},
"infrastructureRoleArn": "string",
"instanceLaunchTemplate": {
"capacityOptionType": "string",
"capacityReservations": {
"reservationGroupArn": "string",
"reservationPreference": "string"
},
"ec2InstanceProfileArn": "string",
"fipsEnabled": boolean,
"instanceMetadataTagsPropagation": boolean,
"instanceRequirements": {
"allowedInstanceTypes": [ "string" ]
},
"localStorageConfiguration": {
"useLocalStorage": boolean
},
"monitoring": "string",
"networkConfiguration": {
"securityGroups": [ "string" ],
"subnets": [ "string" ]
},
"storageConfiguration": {
"storageSizeGiB": number
}
},
"propagateTags": "string"
},
"maxvCpus": number,
"minvCpus": number,
"placementGroup": "string",
"scalingPolicy": {
"minScaleDownDelayMinutes": number
},
"securityGroupIds": [ "string" ],
"spotIamFleetRole": "string",
"subnets": [ "string" ],
"tags": {
"string" : "string"
},
"type": "string"
},
"context": "string",
"ecsSettings": {
"containerInsights": "string"
},
"eksConfiguration": {
"eksClusterArn": "string",
"kubernetesNamespace": "string"
},
"serviceRole": "string",
"state": "string",
"tags": {
"string" : "string"
},
"type": "string",
"unmanagedvCpus": number
}
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. It can be up to 128 characters long. It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_).
Type: String
Required: Yes
- computeResources
-
Details about the compute resources managed by the compute environment. This parameter is required for managed compute environments. For more information, see Compute Environments in the AWS Batch User Guide.
Type: ComputeResource object
Required: No
- context
-
Reserved.
Type: String
Required: No
- ecsSettings
-
The Amazon ECS settings for the compute environment. These settings control CloudWatch Container Insights collection for the compute environment.
Type: EcsSettings object
Required: No
- eksConfiguration
-
The details for the Amazon EKS cluster that supports the compute environment.
Note
To create a compute environment that uses EKS resources, the caller must have permissions to call
eks:DescribeCluster.Type: EksConfiguration 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. For more information, see AWS Batch service IAM role in the AWS Batch User Guide.
Important
If your account already created the AWS Batch service-linked role, that role is used by default for your compute environment unless you specify a different role here. If the AWS Batch service-linked role doesn't exist in your account, and no role is specified here, the service attempts to create the AWS Batch service-linked role in your account.
This automatic service-linked role creation only applies to
MANAGEDcompute environments. ForUNMANAGEDcompute environments, you must explicitly specify aserviceRole.If your specified role has a path other than
/, then you must specify either the full role ARN (recommended) or prefix the role name with the path. For example, if a role with the namebarhas a path of/foo/, specify/foo/baras the role name. For more information, see Friendly names and paths in the IAM User Guide.Note
Depending on how you created your AWS Batch service role, its ARN might contain the
service-rolepath prefix. When you only specify the name of the service role, AWS Batch assumes that your ARN doesn't use theservice-rolepath prefix. Because of this, we recommend that you specify the full ARN of your service role when you create compute environments.Type: String
Required: No
- state
-
The state of the compute environment. A compute environment must be created in the
ENABLEDstate.If the state is
ENABLED, then the compute environment accepts jobs from a queue and can scale out automatically based on queues.If the state is
ENABLED, then the AWS Batch scheduler can attempt to place jobs from an associated job queue on the compute resources within the environment. If the compute environment is managed, then it can scale its instances out or in automatically, based on the job queue demand.If the state is
DISABLED, then the AWS Batch scheduler doesn't attempt to place jobs within the environment. Jobs in aSTARTINGorRUNNINGstate continue to progress normally. Managed compute environments in theDISABLEDstate don't scale out.Note
Compute environments in a
DISABLEDstate may continue to incur billing charges, for example, if they have running instances due to jobs that are still executing or a non-zerominvCpussetting. To prevent additional charges, disable and delete the compute environment.When an instance is idle, the instance scales down to the
minvCpusvalue. However, the instance size doesn't change. For example, consider ac5.8xlargeinstance with aminvCpusvalue of4and adesiredvCpusvalue of36. This instance doesn't scale down to ac5.largeinstance.Type: String
Valid Values:
ENABLED | DISABLEDRequired: No
-
The tags that you apply to the compute environment to help you categorize and organize your resources. Each tag consists of a key and an optional value. For more information, see Tagging AWS Resources in AWS General Reference.
These tags can be updated or removed using the TagResource and UntagResource API operations. These tags don't propagate to the underlying compute resources.
Type: String to string map
Map Entries: Maximum number of 50 items.
Key Length Constraints: Minimum length of 1. Maximum length of 128.
Value Length Constraints: Maximum length of 256.
Required: No
- type
-
The type of the compute environment:
MANAGEDorUNMANAGED. For more information, see Compute Environments in the AWS Batch User Guide.Type: String
Valid Values: