Skip to content

set_instance_health

set_instance_health(
    *,
    config_overrides: Optional[AutoScalingClientConfig] = None,
    instance_id: Optional[XmlStringMaxLen19] = None,
    health_status: Optional[XmlStringMaxLen32] = None,
    should_respect_grace_period: Optional[ShouldRespectGracePeriod] = None,
) -> None

Sets the health status of the specified instance.

For more information, see Set up a custom health check for your Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.

Parameters:

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

    The ID of the instance.

  • health_status (Optional[XmlStringMaxLen32], default: None ) –

    The health status of the instance. Set to Healthy to have the instance remain in service. Set to Unhealthy to have the instance be out of service. Amazon EC2 Auto Scaling terminates and replaces the unhealthy instance.

  • should_respect_grace_period (Optional[ShouldRespectGracePeriod], default: None ) –

    If the Auto Scaling group of the specified instance has a HealthCheckGracePeriod specified for the group, by default, this call respects the grace period. Set this to False, to have the call not respect the grace period associated with the group.

    For more information about the health check grace period, see Set the health check grace period for an Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.

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).

  • UnknownServiceError –

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

Examples:

To set the health status of an instance This example sets the health status of the specified instance to Unhealthy.

>>> client.set_instance_health(instance_id='i-93633f9b', health_status='Unhealthy')
Source code in docs_src/capo_auto_scaling/_services/auto_scaling.py
def set_instance_health(
    self,
    *,
    config_overrides: Optional[AutoScalingClientConfig] = None,
    instance_id: Optional[
        "capo_auto_scaling.types.xml_string_max_len19.XmlStringMaxLen19"
    ] = None,
    health_status: Optional[
        "capo_auto_scaling.types.xml_string_max_len32.XmlStringMaxLen32"
    ] = None,
    should_respect_grace_period: Optional[
        "capo_auto_scaling.types.should_respect_grace_period.ShouldRespectGracePeriod"
    ] = None,
) -> None:
    """<p>Sets the health status of the specified instance.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/set-up-a-custom-health-check.html">Set up a custom health check for your Auto Scaling group</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p>

    Args:
        instance_id: <p>The ID of the instance.</p>
        health_status: <p>The health status of the instance. Set to <code>Healthy</code> to have the instance remain in service. Set to <code>Unhealthy</code> to have the instance be out of service. Amazon EC2 Auto Scaling terminates and replaces the unhealthy instance.</p>
        should_respect_grace_period: <p>If the Auto Scaling group of the specified instance has a <code>HealthCheckGracePeriod</code> specified for the group, by default, this call respects the grace period. Set this to <code>False</code>, to have the call not respect the grace period associated with the group.</p> <p>For more information about the health check grace period, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/health-check-grace-period.html">Set the health check grace period for an Auto Scaling group</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</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.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To set the health status of an instance
        This example sets the health status of the specified instance to Unhealthy.

        >>> client.set_instance_health(instance_id='i-93633f9b', health_status='Unhealthy')
    """

    def _handler(
        req: "OperationRequest[capo_auto_scaling.types.set_instance_health_query.SetInstanceHealthQuery]",
    ) -> OperationResponse[None]:
        import capo_auto_scaling._operations.auto_scaling_2011_01_01.set_instance_health

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("SetInstanceHealth")
    )
    input_: capo_auto_scaling.types.set_instance_health_query.SetInstanceHealthQuery = {}
    if instance_id is not None:
        input_["instance_id"] = instance_id
    if health_status is not None:
        input_["health_status"] = health_status
    if should_respect_grace_period is not None:
        input_["should_respect_grace_period"] = should_respect_grace_period

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