AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
Creates an Batch compute environment. You can create MANAGED
or UNMANAGED
compute environments. MANAGED
compute environments can use Amazon EC2 or Fargate
resources. UNMANAGED
compute environments can only use EC2 resources.
In a managed compute environment, 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.
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 Batch User Guide.
For .NET Core this operation is only available in asynchronous form. Please refer to CreateComputeEnvironmentAsync.
Namespace: Amazon.Batch
Assembly: AWSSDK.Batch.dll
Version: 3.x.y.z
public virtual CreateComputeEnvironmentResponse CreateComputeEnvironment( CreateComputeEnvironmentRequest request )
Container for the necessary parameters to execute the CreateComputeEnvironment service method.
Exception | Condition |
---|---|
ClientException | These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid. |
ServerException | These errors are usually caused by a server issue. |
This example creates a managed compute environment with specific C4 instance types that are launched on demand. The compute environment is called C4OnDemand.
var client = new AmazonBatchClient(); var response = client.CreateComputeEnvironment(new CreateComputeEnvironmentRequest { Type = "MANAGED", ComputeEnvironmentName = "C4OnDemand", ComputeResources = new ComputeResource { Type = "EC2", DesiredvCpus = 48, Ec2KeyPair = "id_rsa", InstanceRole = "ecsInstanceRole", InstanceTypes = new List<string> { "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge" }, MaxvCpus = 128, MinvCpus = 0, SecurityGroupIds = new List<string> { "sg-cf5093b2" }, Subnets = new List<string> { "subnet-220c0e0a", "subnet-1a95556d", "subnet-978f6dce" }, Tags = new Dictionary<string, string> { { "Name", "Batch Instance - C4OnDemand" } } }, ServiceRole = "arn:aws:iam::012345678910:role/AWSBatchServiceRole", State = "ENABLED" }); string computeEnvironmentArn = response.ComputeEnvironmentArn; string computeEnvironmentName = response.ComputeEnvironmentName;
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.
var client = new AmazonBatchClient(); var response = client.CreateComputeEnvironment(new CreateComputeEnvironmentRequest { Type = "MANAGED", ComputeEnvironmentName = "M4Spot", ComputeResources = new ComputeResource { Type = "SPOT", BidPercentage = 20, DesiredvCpus = 4, Ec2KeyPair = "id_rsa", InstanceRole = "ecsInstanceRole", InstanceTypes = new List<string> { "m4" }, MaxvCpus = 128, MinvCpus = 0, SecurityGroupIds = new List<string> { "sg-cf5093b2" }, SpotIamFleetRole = "arn:aws:iam::012345678910:role/aws-ec2-spot-fleet-role", Subnets = new List<string> { "subnet-220c0e0a", "subnet-1a95556d", "subnet-978f6dce" }, Tags = new Dictionary<string, string> { { "Name", "Batch Instance - M4Spot" } } }, ServiceRole = "arn:aws:iam::012345678910:role/AWSBatchServiceRole", State = "ENABLED" }); string computeEnvironmentArn = response.ComputeEnvironmentArn; string computeEnvironmentName = response.ComputeEnvironmentName;
.NET Framework:
Supported in: 4.5 and newer, 3.5