Skip to content

modify_instance_placement async

modify_instance_placement(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    group_name: Optional[PlacementGroupName] = None,
    partition_number: Optional[Integer] = None,
    host_resource_group_arn: Optional[String] = None,
    group_id: Optional[PlacementGroupId] = None,
    instance_id: Optional[InstanceId] = None,
    tenancy: Optional[HostTenancy] = None,
    affinity: Optional[Affinity] = None,
    host_id: Optional[DedicatedHostId] = None,
) -> ModifyInstancePlacementResult

Modifies the placement attributes for a specified instance. You can do the following:

  • Modify the affinity between an instance and a Dedicated Host. When affinity is set to host and the instance is not associated with a specific Dedicated Host, the next time the instance is started, it is automatically associated with the host on which it lands. If the instance is restarted or rebooted, this relationship persists.

  • Change the Dedicated Host with which an instance is associated.

  • Change the instance tenancy of an instance.

  • Move an instance to or from a placement group.

At least one attribute for affinity, host ID, tenancy, or placement group name must be specified in the request. Affinity and tenancy can be modified in the same request.

To modify the host ID, tenancy, placement group, or partition for an instance, the instance must be in the stopped state.

Parameters:

  • group_name (Optional[PlacementGroupName], default: None ) –

    The name of the placement group in which to place the instance. For spread placement groups, the instance must have a tenancy of default. For cluster and partition placement groups, the instance must have a tenancy of default or dedicated.

    To remove an instance from a placement group, specify an empty string ("").

  • partition_number (Optional[Integer], default: None ) –

    The number of the partition in which to place the instance. Valid only if the placement group strategy is set to partition.

  • host_resource_group_arn (Optional[String], default: None ) –

    The ARN of the host resource group in which to place the instance. The instance must have a tenancy of host to specify this parameter.

  • group_id (Optional[PlacementGroupId], default: None ) –

    The Group Id of a placement group. You must specify the Placement Group Group Id to launch an instance in a shared placement group.

  • instance_id (Optional[InstanceId], default: None ) –

    The ID of the instance that you are modifying.

  • tenancy (Optional[HostTenancy], default: None ) –

    The tenancy for the instance.

    For T3 instances, you must launch the instance on a Dedicated Host to use a tenancy of host. You can't change the tenancy from host to dedicated or default. Attempting to make one of these unsupported tenancy changes results in an InvalidRequest error code.

  • affinity (Optional[Affinity], default: None ) –

    The affinity setting for the instance. For more information, see Host affinity in the Amazon EC2 User Guide.

  • host_id (Optional[DedicatedHostId], default: None ) –

    The ID of the Dedicated Host with which to associate the instance.

Raises:

Source code in docs_src/capo_ec2/_services/async_ec2.py
async def modify_instance_placement(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    group_name: Optional[
        "capo_ec2.types.placement_group_name.PlacementGroupName"
    ] = None,
    partition_number: Optional["capo_ec2.types.integer.Integer"] = None,
    host_resource_group_arn: Optional["capo_ec2.types.string.String"] = None,
    group_id: Optional["capo_ec2.types.placement_group_id.PlacementGroupId"] = None,
    instance_id: Optional["capo_ec2.types.instance_id.InstanceId"] = None,
    tenancy: Optional["capo_ec2.types.host_tenancy.HostTenancy"] = None,
    affinity: Optional["capo_ec2.types.affinity.Affinity"] = None,
    host_id: Optional["capo_ec2.types.dedicated_host_id.DedicatedHostId"] = None,
) -> (
    "capo_ec2.types.modify_instance_placement_result.ModifyInstancePlacementResult"
):
    """<p>Modifies the placement attributes for a specified instance. You can do the following:</p> <ul> <li> <p>Modify the affinity between an instance and a <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/dedicated-hosts-overview.html">Dedicated Host</a>. When affinity is set to <code>host</code> and the instance is not associated with a specific Dedicated Host, the next time the instance is started, it is automatically associated with the host on which it lands. If the instance is restarted or rebooted, this relationship persists.</p> </li> <li> <p>Change the Dedicated Host with which an instance is associated.</p> </li> <li> <p>Change the instance tenancy of an instance.</p> </li> <li> <p>Move an instance to or from a <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html">placement group</a>.</p> </li> </ul> <p>At least one attribute for affinity, host ID, tenancy, or placement group name must be specified in the request. Affinity and tenancy can be modified in the same request.</p> <p>To modify the host ID, tenancy, placement group, or partition for an instance, the instance must be in the <code>stopped</code> state.</p>

    Args:
        group_name: <p>The name of the placement group in which to place the instance. For spread placement groups, the instance must have a tenancy of <code>default</code>. For cluster and partition placement groups, the instance must have a tenancy of <code>default</code> or <code>dedicated</code>.</p> <p>To remove an instance from a placement group, specify an empty string ("").</p>
        partition_number: <p>The number of the partition in which to place the instance. Valid only if the placement group strategy is set to <code>partition</code>.</p>
        host_resource_group_arn: <p>The ARN of the host resource group in which to place the instance. The instance must have a tenancy of <code>host</code> to specify this parameter.</p>
        group_id: <p>The Group Id of a placement group. You must specify the Placement Group <b>Group Id</b> to launch an instance in a shared placement group.</p>
        instance_id: <p>The ID of the instance that you are modifying.</p>
        tenancy: <p>The tenancy for the instance.</p> <note> <p>For T3 instances, you must launch the instance on a Dedicated Host to use a tenancy of <code>host</code>. You can't change the tenancy from <code>host</code> to <code>dedicated</code> or <code>default</code>. Attempting to make one of these unsupported tenancy changes results in an <code>InvalidRequest</code> error code.</p> </note>
        affinity: <p>The affinity setting for the instance. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/how-dedicated-hosts-work.html#dedicated-hosts-affinity">Host affinity</a> in the <i>Amazon EC2 User Guide</i>.</p>
        host_id: <p>The ID of the Dedicated Host with which to associate the instance.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.modify_instance_placement_request.ModifyInstancePlacementRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.modify_instance_placement_result.ModifyInstancePlacementResult"
    ]:
        import capo_ec2._operations.amazon_ec2.modify_instance_placement

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.modify_instance_placement.async_modify_instance_placement(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ModifyInstancePlacement")
    )
    input_: capo_ec2.types.modify_instance_placement_request.ModifyInstancePlacementRequest = {}
    if group_name is not None:
        input_["group_name"] = group_name
    if partition_number is not None:
        input_["partition_number"] = partition_number
    if host_resource_group_arn is not None:
        input_["host_resource_group_arn"] = host_resource_group_arn
    if group_id is not None:
        input_["group_id"] = group_id
    if instance_id is not None:
        input_["instance_id"] = instance_id
    if tenancy is not None:
        input_["tenancy"] = tenancy
    if affinity is not None:
        input_["affinity"] = affinity
    if host_id is not None:
        input_["host_id"] = host_id

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output