How to Enable Auto Placement and Host Recovery on EC2?
This article explains how an administrator can enable automatic instance placement and host recovery on an Amazon EC2 Dedicated Host. It outlines the functional purposes of both settings and provides step-by-step instructions for configuring them during initial host allocation or on an existing Dedicated Host using the AWS Management Console, the AWS Command Line Interface, and AWS CloudFormation.
Understanding Automatic Instance Placement and Host Recovery
Amazon EC2 Dedicated Hosts are physical servers with EC2 instance capacity fully dedicated to a single customer's use. When managing Dedicated Hosts, two key configuration settings help streamline operations and improve resiliency:
- Instance auto-placement: Controls whether
untargeted instance launches (instances configured with
hosttenancy that do not specify a particular Dedicated Host ID) can be automatically placed onto the Dedicated Host. When set toon, Amazon EC2 can automatically launch matching instances onto the host. When set tooff, instances can only be launched onto the host if their launch configuration explicitly references the Host ID. - Host recovery: Automatically restarts your instances onto a new, replacement Dedicated Host if the underlying physical server experiences an unexpected hardware failure. The replacement host is allocated on your behalf at no additional charge beyond the standard Dedicated Host rate, and the newly allocated host retains the same instance type or family configuration as the failed host.
Prerequisites and Limitations
Before configuring these settings, verify the following operational parameters:
- Supported Instance Types: Host recovery is supported for most Dedicated Host configurations, though specific bare metal instances or specialized hardware families may have restrictions.
- Capacity Calculation: A Dedicated Host must have available capacity to accept auto-placed instances. If a host supports \(C_{total}\) total vCPUs or sockets and currently utilizes \(C_{used}\), the remaining capacity \(C_{rem}\) is given by: \[C_{rem} = C_{total} - C_{used}\] For single-instance-type Dedicated Hosts, instances must match the exact instance type configured on the host. For multiple-instance-type Dedicated Hosts, instances must belong to the same instance family.
- Storage Requirements: Host recovery is only supported for Amazon EBS-backed instances. Instances backed by instance store volumes are not eligible for automatic host recovery.
Method 1: Using the AWS Management Console
Administrators can enable both settings either when allocating a new Dedicated Host or by modifying an existing one.
During New Host Allocation
- Open the Amazon EC2 console.
- In the navigation pane, choose Dedicated Hosts.
- Select Allocate Dedicated Host.
- Configure the Instance family and Instance type settings according to your workload requirements.
- Locate Instance auto-placement and select Enable.
- Locate Host recovery and select Enable.
- Specify the desired quantity and click Allocate.
Modifying an Existing Dedicated Host
- Open the Amazon EC2 console and navigate to Dedicated Hosts.
- Select the target Dedicated Host from the list.
- Click the Actions dropdown menu and choose Modify host.
- Check the box or select Enable for Instance auto-placement.
- Check the box or select Enable for Host recovery.
- Select Save to apply the changes immediately.
Method 2: Using the AWS CLI
You can automate the configuration of Dedicated Hosts using the AWS Command Line Interface (AWS CLI).
Allocating a New Host with Auto-Placement and Host Recovery
Use the allocate-hosts command and pass
--auto-placement on and
--host-recovery on:
aws ec2 allocate-hosts \
--availability-zone us-east-1a \
--instance-type m5.xlarge \
--quantity 1 \
--auto-placement on \
--host-recovery onTo allow multiple instance types within the same family on the host
while enabling both features, specify --instance-family
instead of --instance-type:
aws ec2 allocate-hosts \
--availability-zone us-east-1a \
--instance-family m5 \
--quantity 1 \
--auto-placement on \
--host-recovery onModifying an Existing Dedicated Host
If the Dedicated Host is already allocated, use the
modify-hosts command along with the target Host ID:
aws ec2 modify-hosts \
--host-ids h-0123456789abcdef0 \
--auto-placement on \
--host-recovery onVerifying the Host Configuration
To confirm that both settings are active, run the
describe-hosts command:
aws ec2 describe-hosts \
--host-ids h-0123456789abcdef0 \
--query "Hosts[*].{HostId:HostId,AutoPlacement:AutoPlacement,HostRecovery:HostRecovery,State:State}" \
--output tableMethod 3: Using AWS CloudFormation
For infrastructure-as-code deployments, define an
AWS::EC2::Host resource in your CloudFormation template and
set AutoPlacement and HostRecovery to
on:
Resources:
ProductionDedicatedHost:
Type: AWS::EC2::Host
Properties:
AvailabilityZone: us-east-1a
InstanceType: c5.large
AutoPlacement: "on"
HostRecovery: "on"Launching Instances to Utilize Auto-Placement
Once automatic placement is enabled on a Dedicated Host, instances
launched with a tenancy of host that do not specify a
HostId will automatically be placed on any available
Dedicated Host with AutoPlacement set to on in
the target Availability Zone:
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--instance-type m5.xlarge \
--placement Tenancy=host,AvailabilityZone=us-east-1a