Tutorial: Launch instances into Capacity Blocks - Amazon Elastic Compute Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Tutorial: Launch instances into Capacity Blocks

This tutorial walks you through the steps that you must perform so that your EC2 Fleet launches instances into Capacity Blocks. For more information about Capacity Blocks, see Capacity Blocks for ML.

You can use EC2 Fleet of type instant to launch instances into Capacity Blocks. For more information, see Use an EC2 Fleet of type 'instant'.

In most cases, the target capacity of the EC2 Fleet request should be less then or equal to the available capacity of the Capacity Block reservation that you are targeting. Target capacity requests that exceed the limits of the Capacity Block reservation will not be fulfilled. If the target capacity request exceeds the limits of your Capacity Block reservation, you will receive an Insufficient Capacity Exception for the capacity that exceeds the limits of your Capacity Block reservation.

Note

For Capacity Blocks, EC2 Fleet will not fallback to launching On-Demand Instances for the remainder of the desired target capacity.

If EC2 Fleet is unable to fulfill the requested target capacity in an available Capacity Block reservation, EC2 Fleet will fulfill as much capacity as it can and return the instances that it was able to launch. You can repeat the call to EC2 Fleet again until all the instances are provisioned.

After configuring the EC2 Fleet request, you must wait until the start date of your Capacity Block reservation. If you make requests to EC2 Fleet to launch into a Capacity Block that hasn't started yet, you will receive an Insufficient Capacity Error.

After your Capacity Block reservation becomes active, you can make EC2 Fleet API calls and provision the instances into your Capacity Block based on the parameters you selected. Instances running in the Capacity Block continue to run until you stop or terminate them through a separate Amazon EC2 API call or until Amazon EC2 terminates the instances when the Capacity Block reservation ends.

Considerations
  • Multiple Capacity Blocks in the same CreateFleet request aren't supported.

  • Using OnDemandTargetCapacity or SpotTargetCapacity while also setting capacity-block as the DefaultTargetCapacity isn't supported.

  • If DefaultTargetCapacityType is set to capacity-block, you can't provide OnDemandOptions::CapacityReservationOptions. An exception will occur.

Create a launch template

The launch template ID is used in the following step. For more information, see Create a launch template.

To configure the launch template, for InstanceMarketOptionsRequest, set MarketType to capacity-block. Specify the Capacity Block reservation ID that you are targeting by setting the CapacityReservationID parameter.

Create the EC2 Fleet

Create a file, config.json, with the following configuration for its EC2 Fleet. In the following example, replace the resource identifiers with your own resource identifiers.

{ "LaunchTemplateConfigs": [ { "LaunchTemplateSpecification": { "LaunchTemplateName": "CBR-launch-template", "Version": "1" }, "Overrides": [ { "InstanceType": "p5.48xlarge", "AvailabilityZone": "us-east-1a" }, ] } ], "TargetCapacitySpecification": { "TotalTargetCapacity": 10, "DefaultTargetCapacityType": "capacity-block" }, "Type": "instant" }

Use the following create-fleet command.

aws ec2 create-fleet \ --cli-input-json file://config.json

For more information, see Create an EC2 Fleet.