| Server IP : 3.96.16.70 / Your IP : 216.73.216.15 Web Server : Apache System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /lib/python3.9/site-packages/awscli/examples/ec2/ |
Upload File : |
**Example 1: To remove an instance's affinity with a Dedicated Host**
The following ``modify-instance-placement`` example removes an instance's affinity with a Dedicated Host and enables it to launch on any available Dedicated Host in your account that supports its instance type. ::
aws ec2 modify-instance-placement \
--instance-id i-0e6ddf6187EXAMPLE \
--affinity default
Output::
{
"Return": true
}
**Example 2: To establish affinity between an instance and the specified Dedicated Host**
The following ``modify-instance-placement`` example establishes a launch relationship between an instance and a Dedicated Host. The instance is only able to run on the specified Dedicated Host. ::
aws ec2 modify-instance-placement \
--instance-id i-0e6ddf6187EXAMPLE \
--affinity host \
--host-id i-0e6ddf6187EXAMPLE
Output::
{
"Return": true
}
**Example 3: To move an instance to a placement group**
The following ``modify-instance-placement`` example moves an instance to a placement group, stop the instance, modify the instance placement, and then restart the instance. ::
aws ec2 stop-instances \
--instance-ids i-0123a456700123456
aws ec2 modify-instance-placement \
--instance-id i-0123a456700123456 \
--group-name MySpreadGroup
aws ec2 start-instances \
--instance-ids i-0123a456700123456
**Example 4: To remove an instance from a placement group**
The following ``modify-instance-placement`` example removes an instance from a placement group by stopping the instance, modifying the instance placement, and then restarting the instance. The following example specifies an empty string ("") for the placement group name to indicate that the instance is not to be located in a placement group.
Stop the instance::
aws ec2 stop-instances \
--instance-ids i-0123a456700123456
Modify the placement (Windows Command Prompt)::
aws ec2 modify-instance-placement \
--instance-id i-0123a456700123456 \
--group-name ""
Modify the placement (Windows PowerShell, Linux, and macOS)::
aws ec2 modify-instance-placement `
--instance-id i-0123a456700123456 `
--group-name ''
Restart the instance::
aws ec2 start-instances \
--instance-ids i-0123a456700123456
Output::
{
"Return": true
}
For more information, see `Modify Dedicated Host tenancy and affinity <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/moving-instances-dedicated-hosts.html>`__ in the *Amazon EC2 User Guide*.