ComputeResources

class aws_cdk.aws_batch.ComputeResources(*, vpc, allocation_strategy=None, bid_percentage=None, compute_resources_tags=None, desiredv_cpus=None, ec2_key_pair=None, image=None, instance_role=None, instance_types=None, launch_template=None, maxv_cpus=None, minv_cpus=None, placement_group=None, security_groups=None, spot_fleet_role=None, type=None, vpc_subnets=None)

Bases: object

(experimental) Properties for defining the structure of the batch compute cluster.

Parameters:
  • vpc (IVpc) – (experimental) The VPC network that all compute resources will be connected to.

  • allocation_strategy (Optional[AllocationStrategy]) – (experimental) The allocation strategy to use for the compute resource in case not enough instances of the best fitting instance type can be allocated. This could be due to availability of the instance type in the region or Amazon EC2 service limits. If this is not specified, the default for the EC2 ComputeResourceType is BEST_FIT, which will use only the best fitting instance type, waiting for additional capacity if it’s not available. This allocation strategy keeps costs lower but can limit scaling. If you are using Spot Fleets with BEST_FIT then the Spot Fleet IAM Role must be specified. BEST_FIT_PROGRESSIVE will select an additional instance type that is large enough to meet the requirements of the jobs in the queue, with a preference for an instance type with a lower cost. The default value for the SPOT instance type is SPOT_CAPACITY_OPTIMIZED, which is only available for for this type of compute resources and will select an additional instance type that is large enough to meet the requirements of the jobs in the queue, with a preference for an instance type that is less likely to be interrupted. Default: AllocationStrategy.BEST_FIT

  • bid_percentage (Union[int, float, None]) – (experimental) This property will be ignored if you set the environment type to ON_DEMAND. The maximum percentage that a Spot Instance price can be when compared with the On-Demand price for that instance type before instances are launched. For example, if your maximum percentage is 20%, then the Spot price must be below 20% of the current On-Demand price for that EC2 instance. You always pay the lowest (market) price and never more than your maximum percentage. If you leave this field empty, the default value is 100% of the On-Demand price. Default: 100

  • compute_resources_tags (Optional[Mapping[str, str]]) – (experimental) Key-value pair tags to be applied to resources that are launched in the compute environment. For AWS Batch, these take the form of “String1”: “String2”, where String1 is the tag key and String2 is the tag value—for example, { “Name”: “AWS Batch Instance - C4OnDemand” }. Default: - no tags will be assigned on compute resources.

  • desiredv_cpus (Union[int, float, None]) – (experimental) The desired number of EC2 vCPUS in the compute environment. Default: - no desired vcpu value will be used.

  • ec2_key_pair (Optional[str]) – (experimental) The EC2 key pair that is used for instances launched in the compute environment. If no key is defined, then SSH access is not allowed to provisioned compute resources. Default: - no SSH access will be possible.

  • image (Optional[IMachineImage]) – (experimental) The Amazon Machine Image (AMI) ID used for instances launched in the compute environment. Default: - no image will be used.

  • instance_role (Optional[str]) – (experimental) The Amazon ECS instance profile applied to Amazon EC2 instances in a compute environment. You can specify the short name or full Amazon Resource Name (ARN) of an instance profile. For example, ecsInstanceRole or arn:aws:iam::<aws_account_id>:instance-profile/ecsInstanceRole . For more information, see Amazon ECS Instance Role in the AWS Batch User Guide. Default: - a new role will be created.

  • instance_types (Optional[Sequence[InstanceType]]) – (experimental) The types of EC2 instances that may be launched in the compute environment. You can specify instance families to launch any instance type within those families (for example, c4 or p3), or you can specify specific sizes within a family (such as c4.8xlarge). You can also choose optimal to pick instance types (from the C, M, and R instance families) on the fly that match the demand of your job queues. Default: optimal

  • launch_template (Union[LaunchTemplateSpecification, Dict[str, Any], None]) – (experimental) An optional launch template to associate with your compute resources. For more information, see README file. Default: - no custom launch template will be used

  • maxv_cpus (Union[int, float, None]) – (experimental) The maximum number of EC2 vCPUs that an environment can reach. Each vCPU is equivalent to 1,024 CPU shares. You must specify at least one vCPU. Default: 256

  • minv_cpus (Union[int, float, None]) – (experimental) The minimum number of EC2 vCPUs that an environment should maintain (even if the compute environment state is DISABLED). Each vCPU is equivalent to 1,024 CPU shares. By keeping this set to 0 you will not have instance time wasted when there is no work to be run. If you set this above zero you will maintain that number of vCPUs at all times. Default: 0

  • placement_group (Optional[str]) – (experimental) The Amazon EC2 placement group to associate with your compute resources. Default: - No placement group will be used.

  • security_groups (Optional[Sequence[ISecurityGroup]]) – (experimental) The EC2 security group(s) associated with instances launched in the compute environment. Default: - AWS default security group.

  • spot_fleet_role (Optional[IRole]) – (experimental) This property will be ignored if you set the environment type to ON_DEMAND. The Amazon Resource Name (ARN) of the Amazon EC2 Spot Fleet IAM role applied to a SPOT compute environment. For more information, see Amazon EC2 Spot Fleet Role in the AWS Batch User Guide. Default: - no fleet role will be used.

  • type (Optional[ComputeResourceType]) – (experimental) The type of compute environment: ON_DEMAND, SPOT, FARGATE, or FARGATE_SPOT. Default: ON_DEMAND

  • vpc_subnets (Union[SubnetSelection, Dict[str, Any], None]) – (experimental) The VPC subnets into which the compute resources are launched. Default: - private subnets of the supplied VPC.

Stability:

experimental

ExampleMetadata:

infused

Example:

# vpc: ec2.Vpc

my_compute_env = batch.ComputeEnvironment(self, "ComputeEnv",
    compute_resources=batch.ComputeResources(
        image=ecs.EcsOptimizedAmi(
            generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2
        ),
        vpc=vpc
    )
)

Attributes

allocation_strategy

(experimental) The allocation strategy to use for the compute resource in case not enough instances of the best fitting instance type can be allocated.

This could be due to availability of the instance type in the region or Amazon EC2 service limits. If this is not specified, the default for the EC2 ComputeResourceType is BEST_FIT, which will use only the best fitting instance type, waiting for additional capacity if it’s not available. This allocation strategy keeps costs lower but can limit scaling. If you are using Spot Fleets with BEST_FIT then the Spot Fleet IAM Role must be specified. BEST_FIT_PROGRESSIVE will select an additional instance type that is large enough to meet the requirements of the jobs in the queue, with a preference for an instance type with a lower cost. The default value for the SPOT instance type is SPOT_CAPACITY_OPTIMIZED, which is only available for for this type of compute resources and will select an additional instance type that is large enough to meet the requirements of the jobs in the queue, with a preference for an instance type that is less likely to be interrupted.

Default:

AllocationStrategy.BEST_FIT

Stability:

experimental

bid_percentage

(experimental) This property will be ignored if you set the environment type to ON_DEMAND.

The maximum percentage that a Spot Instance price can be when compared with the On-Demand price for that instance type before instances are launched. For example, if your maximum percentage is 20%, then the Spot price must be below 20% of the current On-Demand price for that EC2 instance. You always pay the lowest (market) price and never more than your maximum percentage. If you leave this field empty, the default value is 100% of the On-Demand price.

Default:

100

Stability:

experimental

compute_resources_tags

(experimental) Key-value pair tags to be applied to resources that are launched in the compute environment.

For AWS Batch, these take the form of “String1”: “String2”, where String1 is the tag key and String2 is the tag value—for example, { “Name”: “AWS Batch Instance - C4OnDemand” }.

Default:
  • no tags will be assigned on compute resources.

Stability:

experimental

desiredv_cpus

(experimental) The desired number of EC2 vCPUS in the compute environment.

Default:
  • no desired vcpu value will be used.

Stability:

experimental

ec2_key_pair

(experimental) The EC2 key pair that is used for instances launched in the compute environment.

If no key is defined, then SSH access is not allowed to provisioned compute resources.

Default:
  • no SSH access will be possible.

Stability:

experimental

image

(experimental) The Amazon Machine Image (AMI) ID used for instances launched in the compute environment.

Default:
  • no image will be used.

Stability:

experimental

instance_role

(experimental) The Amazon ECS instance profile applied to Amazon EC2 instances in a compute environment.

You can specify the short name or full Amazon Resource Name (ARN) of an instance profile. For example, ecsInstanceRole or arn:aws:iam::<aws_account_id>:instance-profile/ecsInstanceRole . For more information, see Amazon ECS Instance Role in the AWS Batch User Guide.

Default:
  • a new role will be created.

Stability:

experimental

Link:

https://docs.aws.amazon.com/batch/latest/userguide/instance_IAM_role.html

instance_types

(experimental) The types of EC2 instances that may be launched in the compute environment.

You can specify instance families to launch any instance type within those families (for example, c4 or p3), or you can specify specific sizes within a family (such as c4.8xlarge). You can also choose optimal to pick instance types (from the C, M, and R instance families) on the fly that match the demand of your job queues.

Default:

optimal

Stability:

experimental

launch_template

(experimental) An optional launch template to associate with your compute resources.

For more information, see README file.

Default:
  • no custom launch template will be used

Stability:

experimental

Link:

https://docs.aws.amazon.com/batch/latest/userguide/launch-templates.html

maxv_cpus

(experimental) The maximum number of EC2 vCPUs that an environment can reach.

Each vCPU is equivalent to 1,024 CPU shares. You must specify at least one vCPU.

Default:

256

Stability:

experimental

minv_cpus

(experimental) The minimum number of EC2 vCPUs that an environment should maintain (even if the compute environment state is DISABLED).

Each vCPU is equivalent to 1,024 CPU shares. By keeping this set to 0 you will not have instance time wasted when there is no work to be run. If you set this above zero you will maintain that number of vCPUs at all times.

Default:

0

Stability:

experimental

placement_group

(experimental) The Amazon EC2 placement group to associate with your compute resources.

Default:
  • No placement group will be used.

Stability:

experimental

security_groups

(experimental) The EC2 security group(s) associated with instances launched in the compute environment.

Default:
  • AWS default security group.

Stability:

experimental

spot_fleet_role

(experimental) This property will be ignored if you set the environment type to ON_DEMAND.

The Amazon Resource Name (ARN) of the Amazon EC2 Spot Fleet IAM role applied to a SPOT compute environment. For more information, see Amazon EC2 Spot Fleet Role in the AWS Batch User Guide.

Default:
  • no fleet role will be used.

Stability:

experimental

Link:

https://docs.aws.amazon.com/batch/latest/userguide/spot_fleet_IAM_role.html

type

ON_DEMAND, SPOT, FARGATE, or FARGATE_SPOT.

Default:

ON_DEMAND

Stability:

experimental

Type:

(experimental) The type of compute environment

vpc

(experimental) The VPC network that all compute resources will be connected to.

Stability:

experimental

vpc_subnets

(experimental) The VPC subnets into which the compute resources are launched.

Default:
  • private subnets of the supplied VPC.

Stability:

experimental