Starts an instance refresh.
This operation is part of the instance refresh feature in Amazon EC2 Auto Scaling, which helps you update instances in your Auto Scaling group. This feature is helpful, for example, when you have a new AMI or a new user data script. You just need to create a new launch template that specifies the new AMI or user data script. Then start an instance refresh to immediately begin the process of updating instances in the group.
If successful, the request's response contains a unique ID that you can use to track the progress of the instance refresh. To query its status, call the DescribeInstanceRefreshes API. To describe the instance refreshes that have already run, call the DescribeInstanceRefreshes API. To cancel an instance refresh that is in progress, use the CancelInstanceRefresh API.
An instance refresh might fail for several reasons, such as EC2 launch failures, misconfigured health checks, or not ignoring or allowing the termination of instances that are in Standby state or protected from scale in. You can monitor for failed EC2 launches using the scaling activities. To find the scaling activities, call the DescribeScalingActivities API.
If you enable auto rollback, your Auto Scaling group will be rolled back automatically when the instance refresh fails. You can enable this feature before starting an instance refresh by specifying the AutoRollback property in the instance refresh preferences. Otherwise, to roll back an instance refresh before it finishes, use the RollbackInstanceRefresh API.
Parameters:
-
auto_scaling_group_name
(Optional[XmlStringMaxLen255], default:
None
)
–
The name of the Auto Scaling group.
-
strategy
(Optional[RefreshStrategy], default:
None
)
–
The strategy to use for the instance refresh. The default value is Rolling.
-
desired_configuration
(Optional[DesiredConfiguration], default:
None
)
–
The desired configuration. For example, the desired configuration can specify a new launch template or a new version of the current launch template.
Once the instance refresh succeeds, Amazon EC2 Auto Scaling updates the settings of the Auto Scaling group to reflect the new desired configuration.
When you specify a new launch template or a new version of the current launch template for your desired configuration, consider enabling the SkipMatching property in preferences. If it's enabled, Amazon EC2 Auto Scaling skips replacing instances that already use the specified launch template and instance types. This can help you reduce the number of replacements that are required to apply updates.
-
preferences
(Optional[RefreshPreferences], default:
None
)
–
Sets your preferences for the instance refresh so that it performs as expected when you start it. Includes the instance warmup time, the minimum and maximum healthy percentages, and the behaviors that you want Amazon EC2 Auto Scaling to use if instances that are in Standby state or protected from scale in are found. You can also choose to enable additional features, such as the following:
-
Auto rollback
-
Checkpoints
-
CloudWatch alarms
-
Skip matching
-
Bake time
Raises:
-
InstanceRefreshInProgressFault
–
The request failed because an active instance refresh already exists for the specified Auto Scaling group.
-
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 start an instance refresh
This example starts an instance refresh for the specified Auto Scaling group.
>>> await client.start_instance_refresh(auto_scaling_group_name='my-auto-scaling-group', desired_configuration={'LaunchTemplate': {'LaunchTemplateName': 'my-template-for-auto-scaling', 'Version': '$Latest'}}, preferences={'AutoRollback': True, 'InstanceWarmup': 200, 'MinHealthyPercentage': 90, 'MaxHealthyPercentage': 120, 'AlarmSpecification': {'Alarms': ['my-alarm']}})
Source code in docs_src/capo_auto_scaling/_services/async_auto_scaling.py
| async def start_instance_refresh(
self,
*,
config_overrides: Optional[AsyncAutoScalingClientConfig] = None,
auto_scaling_group_name: Optional[
"capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
] = None,
strategy: Optional[
"capo_auto_scaling.types.refresh_strategy.RefreshStrategy"
] = None,
desired_configuration: Optional[
"capo_auto_scaling.types.desired_configuration.DesiredConfiguration"
] = None,
preferences: Optional[
"capo_auto_scaling.types.refresh_preferences.RefreshPreferences"
] = None,
) -> "capo_auto_scaling.types.start_instance_refresh_answer.StartInstanceRefreshAnswer":
"""<p>Starts an instance refresh.</p> <p>This operation is part of the <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-refresh.html">instance refresh feature</a> in Amazon EC2 Auto Scaling, which helps you update instances in your Auto Scaling group. This feature is helpful, for example, when you have a new AMI or a new user data script. You just need to create a new launch template that specifies the new AMI or user data script. Then start an instance refresh to immediately begin the process of updating instances in the group. </p> <p>If successful, the request's response contains a unique ID that you can use to track the progress of the instance refresh. To query its status, call the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeInstanceRefreshes.html">DescribeInstanceRefreshes</a> API. To describe the instance refreshes that have already run, call the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeInstanceRefreshes.html">DescribeInstanceRefreshes</a> API. To cancel an instance refresh that is in progress, use the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_CancelInstanceRefresh.html">CancelInstanceRefresh</a> API. </p> <p>An instance refresh might fail for several reasons, such as EC2 launch failures, misconfigured health checks, or not ignoring or allowing the termination of instances that are in <code>Standby</code> state or protected from scale in. You can monitor for failed EC2 launches using the scaling activities. To find the scaling activities, call the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeScalingActivities.html">DescribeScalingActivities</a> API.</p> <p>If you enable auto rollback, your Auto Scaling group will be rolled back automatically when the instance refresh fails. You can enable this feature before starting an instance refresh by specifying the <code>AutoRollback</code> property in the instance refresh preferences. Otherwise, to roll back an instance refresh before it finishes, use the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_RollbackInstanceRefresh.html">RollbackInstanceRefresh</a> API. </p>
Args:
auto_scaling_group_name: <p>The name of the Auto Scaling group.</p>
strategy: <p>The strategy to use for the instance refresh. The default value is <code>Rolling</code>.</p>
desired_configuration: <p>The desired configuration. For example, the desired configuration can specify a new launch template or a new version of the current launch template.</p> <p>Once the instance refresh succeeds, Amazon EC2 Auto Scaling updates the settings of the Auto Scaling group to reflect the new desired configuration. </p> <note> <p>When you specify a new launch template or a new version of the current launch template for your desired configuration, consider enabling the <code>SkipMatching</code> property in preferences. If it's enabled, Amazon EC2 Auto Scaling skips replacing instances that already use the specified launch template and instance types. This can help you reduce the number of replacements that are required to apply updates. </p> </note>
preferences: <p>Sets your preferences for the instance refresh so that it performs as expected when you start it. Includes the instance warmup time, the minimum and maximum healthy percentages, and the behaviors that you want Amazon EC2 Auto Scaling to use if instances that are in <code>Standby</code> state or protected from scale in are found. You can also choose to enable additional features, such as the following:</p> <ul> <li> <p>Auto rollback</p> </li> <li> <p>Checkpoints</p> </li> <li> <p>CloudWatch alarms</p> </li> <li> <p>Skip matching</p> </li> <li> <p>Bake time</p> </li> </ul>
Raises:
capo_auto_scaling.errors.instance_refresh_in_progress_fault.InstanceRefreshInProgressFault: <p>The request failed because an active instance refresh already exists for the specified Auto Scaling group.</p>
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 start an instance refresh
This example starts an instance refresh for the specified Auto Scaling group.
>>> await client.start_instance_refresh(auto_scaling_group_name='my-auto-scaling-group', desired_configuration={'LaunchTemplate': {'LaunchTemplateName': 'my-template-for-auto-scaling', 'Version': '$Latest'}}, preferences={'AutoRollback': True, 'InstanceWarmup': 200, 'MinHealthyPercentage': 90, 'MaxHealthyPercentage': 120, 'AlarmSpecification': {'Alarms': ['my-alarm']}})
"""
async def _handler(
req: "AsyncOperationRequest[capo_auto_scaling.types.start_instance_refresh_type.StartInstanceRefreshType]",
) -> AsyncOperationResponse[
"capo_auto_scaling.types.start_instance_refresh_answer.StartInstanceRefreshAnswer"
]:
import capo_auto_scaling._operations.auto_scaling_2011_01_01.start_instance_refresh
(
output,
http_response,
) = await capo_auto_scaling._operations.auto_scaling_2011_01_01.start_instance_refresh.async_start_instance_refresh(
req.options, req.input
)
return AsyncOperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("StartInstanceRefresh")
)
input_: capo_auto_scaling.types.start_instance_refresh_type.StartInstanceRefreshType = {}
if auto_scaling_group_name is not None:
input_["auto_scaling_group_name"] = auto_scaling_group_name
if strategy is not None:
input_["strategy"] = strategy
if desired_configuration is not None:
input_["desired_configuration"] = desired_configuration
if preferences is not None:
input_["preferences"] = preferences
response = await aexecute_pipeline(
AsyncOperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
await response.response.aclose()
return response.output
|