create_compute_environment
¶
create_compute_environment(
*,
config_overrides: Optional[BatchClientConfig] = None,
compute_environment_name: Optional[String] = None,
type: Optional[CEType] = None,
state: Optional[CEState] = None,
unmanagedv_cpus: Optional[Integer] = None,
compute_resources: Optional[ComputeResource] = None,
service_role: Optional[String] = None,
tags: Optional[TagrisTagsMap] = None,
eks_configuration: Optional[EksConfiguration] = None,
context: Optional[String] = None,
ecs_settings: Optional[EcsSettings] = None,
) -> CreateComputeEnvironmentResponse
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.
Parameters:
-
compute_environment_name(Optional[String], default:None) –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(Optional[CEType], default:None) –The type of the compute environment:
MANAGEDorUNMANAGED. For more information, see Compute Environments in the Batch User Guide. -
state(Optional[CEState], default:None) –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 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 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.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. -
unmanagedv_cpus(Optional[Integer], default:None) –The maximum number of vCPUs for an unmanaged compute environment. This parameter is only used for fair-share scheduling to reserve vCPU capacity for new share identifiers. If this parameter isn't provided for a fair-share job queue, no vCPU capacity is reserved.
This parameter is only supported when the
typeparameter is set toUNMANAGED. -
compute_resources(Optional[ComputeResource], default:None) –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 Batch User Guide.
-
service_role(Optional[String], default:None) –The full Amazon Resource Name (ARN) of the IAM role that allows Batch to make calls to other Amazon Web Services services on your behalf. For more information, see Batch service IAM role in the Batch User Guide.
If your account already created the Batch service-linked role, that role is used by default for your compute environment unless you specify a different role here. If the Batch service-linked role doesn't exist in your account, and no role is specified here, the service attempts to create the 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.Depending on how you created your Batch service role, its ARN might contain the
service-rolepath prefix. When you only specify the name of the service role, 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. -
tags(Optional[TagrisTagsMap], default:None) –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 Amazon Web Services Resources in Amazon Web Services 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.
-
eks_configuration(Optional[EksConfiguration], default:None) –The details for the Amazon EKS cluster that supports the compute environment.
To create a compute environment that uses EKS resources, the caller must have permissions to call
eks:DescribeCluster. Additional Amazon EKS permissions are required for Batch to manage an access entry on the cluster; see Amazon EKS access entry authentication in the Batch User Guide. -
context(Optional[String], default:None) –Reserved.
-
ecs_settings(Optional[EcsSettings], default:None) –The Amazon ECS settings for the compute environment. These settings control CloudWatch Container Insights collection for the compute environment.
Raises:
-
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.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To create a managed EC2 compute environment This example creates a managed compute environment with specific C4 instance types that are launched on demand. The compute environment is called C4OnDemand.
>>> client.create_compute_environment(compute_environment_name='C4OnDemand', state='ENABLED', type='MANAGED', compute_resources={'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'}, service_role='arn:aws:iam::012345678910:role/AWSBatchServiceRole')
To create a managed EC2 Spot compute environment
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.
>>> client.create_compute_environment(compute_environment_name='M4Spot', state='ENABLED', type='MANAGED', compute_resources={'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'}, service_role='arn:aws:iam::012345678910:role/AWSBatchServiceRole')
To create an ECS Managed Instances compute environment with capacity reservations
This example creates an ECS Managed Instances compute environment that targets On-Demand Capacity Reservations for predictable capacity.
>>> client.create_compute_environment(compute_environment_name='my-reserved-managed-instances-ce', state='ENABLED', type='MANAGED', compute_resources={'type': 'ECS_MANAGED_INSTANCES', 'maxvCpus': 512, 'managedInstancesProvider': {'infrastructureRoleArn': 'arn:aws:iam::123456789012:role/ecsInfrastructureRole', 'instanceLaunchTemplate': {'ec2InstanceProfileArn': 'arn:aws:iam::123456789012:instance-profile/ecsInstanceProfile', 'networkConfiguration': {'subnets': ['subnet-abcde012', 'subnet-bcde012a'], 'securityGroups': ['sg-abcde012']}, 'instanceRequirements': {'allowedInstanceTypes': ['m5.xlarge', 'm5.2xlarge']}, 'capacityReservations': {'reservationGroupArn': 'arn:aws:ec2:us-east-1:123456789012:capacity-reservation-group/my-reservation-group', 'reservationPreference': 'RESERVATIONS_FIRST'}}}})
To create an ECS Managed Instances compute environment
This example creates a managed compute environment that uses ECS Managed Instances.
>>> client.create_compute_environment(compute_environment_name='my-managed-instances-ce', state='ENABLED', type='MANAGED', compute_resources={'type': 'ECS_MANAGED_INSTANCES', 'maxvCpus': 256, 'managedInstancesProvider': {'infrastructureRoleArn': 'arn:aws:iam::123456789012:role/ecsInfrastructureRole', 'instanceLaunchTemplate': {'ec2InstanceProfileArn': 'arn:aws:iam::123456789012:instance-profile/ecsInstanceProfile', 'networkConfiguration': {'subnets': ['subnet-abcde012', 'subnet-bcde012a'], 'securityGroups': ['sg-abcde012']}}}})
To create an ECS Managed Instances Spot compute environment
This example creates a Spot-backed ECS Managed Instances compute environment constrained to specific instance types.
>>> client.create_compute_environment(compute_environment_name='my-spot-managed-instances-ce', state='ENABLED', type='MANAGED', compute_resources={'type': 'ECS_MANAGED_INSTANCES', 'maxvCpus': 1000, 'managedInstancesProvider': {'infrastructureRoleArn': 'arn:aws:iam::123456789012:role/ecsInfrastructureRole', 'instanceLaunchTemplate': {'ec2InstanceProfileArn': 'arn:aws:iam::123456789012:instance-profile/ecsInstanceProfile', 'networkConfiguration': {'subnets': ['subnet-abcde012', 'subnet-bcde012a'], 'securityGroups': ['sg-abcde012']}, 'instanceRequirements': {'allowedInstanceTypes': ['m5.large', 'm5.xlarge', 'm6i.large', 'm6i.xlarge']}, 'capacityOptionType': 'SPOT'}}})
Source code in docs_src/capo_batch/_services/batch.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |