Skip to content

attach_instances

attach_instances(
    *,
    config_overrides: Optional[AutoScalingClientConfig] = None,
    instance_ids: Optional[InstanceIds] = None,
    auto_scaling_group_name: Optional[XmlStringMaxLen255] = None,
) -> None

Attaches one or more EC2 instances to the specified Auto Scaling group.

When you attach instances, Amazon EC2 Auto Scaling increases the desired capacity of the group by the number of instances being attached. If the number of instances being attached plus the desired capacity of the group exceeds the maximum size of the group, the operation fails.

If there is a Classic Load Balancer attached to your Auto Scaling group, the instances are also registered with the load balancer. If there are target groups attached to your Auto Scaling group, the instances are also registered with the target groups.

For more information, see Detach or attach instances in the Amazon EC2 Auto Scaling User Guide.

Parameters:

  • instance_ids (Optional[InstanceIds], default: None ) –

    The IDs of the instances. You can specify up to 20 instances.

  • auto_scaling_group_name (Optional[XmlStringMaxLen255], default: None ) –

    The name of the Auto Scaling group.

Raises:

  • ResourceContentionFault –

    You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).

  • ServiceLinkedRoleFailure –

    The service-linked role is not yet ready for use.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To attach an instance to an Auto Scaling group This example attaches the specified instance to the specified Auto Scaling group.

>>> client.attach_instances(instance_ids=['i-93633f9b'], auto_scaling_group_name='my-auto-scaling-group')
Source code in docs_src/capo_auto_scaling/_services/auto_scaling.py
def attach_instances(
    self,
    *,
    config_overrides: Optional[AutoScalingClientConfig] = None,
    instance_ids: Optional[
        "capo_auto_scaling.types.instance_ids.InstanceIds"
    ] = None,
    auto_scaling_group_name: Optional[
        "capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
    ] = None,
) -> None:
    """<p>Attaches one or more EC2 instances to the specified Auto Scaling group.</p> <p>When you attach instances, Amazon EC2 Auto Scaling increases the desired capacity of the group by the number of instances being attached. If the number of instances being attached plus the desired capacity of the group exceeds the maximum size of the group, the operation fails.</p> <p>If there is a Classic Load Balancer attached to your Auto Scaling group, the instances are also registered with the load balancer. If there are target groups attached to your Auto Scaling group, the instances are also registered with the target groups.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-detach-attach-instances.html">Detach or attach instances</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p>

    Args:
        instance_ids: <p>The IDs of the instances. You can specify up to 20 instances.</p>
        auto_scaling_group_name: <p>The name of the Auto Scaling group.</p>

    Raises:
        capo_auto_scaling.errors.resource_contention_fault.ResourceContentionFault: <p>You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).</p>
        capo_auto_scaling.errors.service_linked_role_failure.ServiceLinkedRoleFailure: <p>The service-linked role is not yet ready for use.</p>
        capo_auto_scaling.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To attach an instance to an Auto Scaling group
        This example attaches the specified instance to the specified Auto Scaling group.

        >>> client.attach_instances(instance_ids=['i-93633f9b'], auto_scaling_group_name='my-auto-scaling-group')
    """

    def _handler(
        req: "OperationRequest[capo_auto_scaling.types.attach_instances_query.AttachInstancesQuery]",
    ) -> OperationResponse[None]:
        import capo_auto_scaling._operations.auto_scaling_2011_01_01.attach_instances

        output, http_response = (
            capo_auto_scaling._operations.auto_scaling_2011_01_01.attach_instances.attach_instances(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AttachInstances")
    )
    input_: capo_auto_scaling.types.attach_instances_query.AttachInstancesQuery = {}
    if instance_ids is not None:
        input_["instance_ids"] = instance_ids
    if auto_scaling_group_name is not None:
        input_["auto_scaling_group_name"] = auto_scaling_group_name

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output