Updates the instance protection settings of the specified instances. This operation cannot be called on instances in a warm pool.
For more information, see Use instance scale-in protection in the Amazon EC2 Auto Scaling User Guide.
If you exceed your maximum limit of instance IDs, which is 50 per Auto Scaling group, the call fails.
Parameters:
-
instance_ids
(Optional[InstanceIds], default:
None
)
–
One or more instance IDs. You can specify up to 50 instances.
-
auto_scaling_group_name
(Optional[XmlStringMaxLen255], default:
None
)
–
The name of the Auto Scaling group.
-
protected_from_scale_in
(Optional[ProtectedFromScaleIn], default:
None
)
–
Indicates whether the instance is protected from termination by Amazon EC2 Auto Scaling when scaling in.
Raises:
-
LimitExceededFault
–
You have already reached a limit for your Amazon EC2 Auto Scaling resources (for example, Auto Scaling groups, launch configurations, or lifecycle hooks). For more information, see DescribeAccountLimits in the Amazon EC2 Auto Scaling API Reference.
-
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 enable instance protection for an instance
This example enables instance protection for the specified instance.
>>> await client.set_instance_protection(instance_ids=['i-93633f9b'], auto_scaling_group_name='my-auto-scaling-group', protected_from_scale_in=True)
To disable instance protection for an instance
This example disables instance protection for the specified instance.
>>> await client.set_instance_protection(instance_ids=['i-93633f9b'], auto_scaling_group_name='my-auto-scaling-group', protected_from_scale_in=False)
Source code in docs_src/capo_auto_scaling/_services/async_auto_scaling.py
| async def set_instance_protection(
self,
*,
config_overrides: Optional[AsyncAutoScalingClientConfig] = 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,
protected_from_scale_in: Optional[
"capo_auto_scaling.types.protected_from_scale_in.ProtectedFromScaleIn"
] = None,
) -> "capo_auto_scaling.types.set_instance_protection_answer.SetInstanceProtectionAnswer":
"""<p>Updates the instance protection settings of the specified instances. This operation cannot be called on instances in a warm pool.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-protection.html">Use instance scale-in protection</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p> <p>If you exceed your maximum limit of instance IDs, which is 50 per Auto Scaling group, the call fails.</p>
Args:
instance_ids: <p>One or more instance IDs. You can specify up to 50 instances.</p>
auto_scaling_group_name: <p>The name of the Auto Scaling group.</p>
protected_from_scale_in: <p>Indicates whether the instance is protected from termination by Amazon EC2 Auto Scaling when scaling in.</p>
Raises:
capo_auto_scaling.errors.limit_exceeded_fault.LimitExceededFault: <p>You have already reached a limit for your Amazon EC2 Auto Scaling resources (for example, Auto Scaling groups, launch configurations, or lifecycle hooks). For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeAccountLimits.html">DescribeAccountLimits</a> in the <i>Amazon EC2 Auto Scaling API Reference</i>.</p>
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 enable instance protection for an instance
This example enables instance protection for the specified instance.
>>> await client.set_instance_protection(instance_ids=['i-93633f9b'], auto_scaling_group_name='my-auto-scaling-group', protected_from_scale_in=True)
To disable instance protection for an instance
This example disables instance protection for the specified instance.
>>> await client.set_instance_protection(instance_ids=['i-93633f9b'], auto_scaling_group_name='my-auto-scaling-group', protected_from_scale_in=False)
"""
async def _handler(
req: "AsyncOperationRequest[capo_auto_scaling.types.set_instance_protection_query.SetInstanceProtectionQuery]",
) -> AsyncOperationResponse[
"capo_auto_scaling.types.set_instance_protection_answer.SetInstanceProtectionAnswer"
]:
import capo_auto_scaling._operations.auto_scaling_2011_01_01.set_instance_protection
(
output,
http_response,
) = await capo_auto_scaling._operations.auto_scaling_2011_01_01.set_instance_protection.async_set_instance_protection(
req.options, req.input
)
return AsyncOperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("SetInstanceProtection")
)
input_: capo_auto_scaling.types.set_instance_protection_query.SetInstanceProtectionQuery = {}
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
if protected_from_scale_in is not None:
input_["protected_from_scale_in"] = protected_from_scale_in
response = await aexecute_pipeline(
AsyncOperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
await response.response.aclose()
return response.output
|