AWS EC2 Auto-recovery is a feature that can help you minimize downtime by automatically recovering an EC2 instance if it becomes impaired due to an underlying hardware or software failure. Auto-recovery can be configured for both EC2 instances and instance fleets.
Here are the steps to configure Auto-recovery for an EC2 instance using both the AWS Management Console and the AWS CLI:
AWS Management Console
- Go to the EC2 Dashboard in the AWS Management Console.
- Select the instance for which you want to enable Auto-recovery.
- Click on the “Actions” button at the top of the screen and select “Instance Settings” > “Add/Modify Auto Recovery”.
- In the “Add/Modify Auto Recovery” dialog box, check the box next to “Enable auto recovery” and enter the number of minutes to wait before attempting to recover the instance. You can also select an SNS topic to receive notifications when an instance is recovered.
- Click the “Enable” button to save the settings.
AWS CLI
- To enable Auto-recovery for an EC2 instance, use the
modify-instance-metadata-options
command:
aws ec2 modify-instance-metadata-options --instance-id <INSTANCE_ID> --http-tokens required --http-endpoint enabled --http-put-response-hop-limit 1 --metadata-http-put-response-hop-limit 1 --auto-recovery-enabled true --auto-recovery-timeout 5 --region <REGION>
Replace <INSTANCE_ID>
with the ID of the EC2 instance you want to enable Auto-recovery for, and <REGION>
with the AWS region where the instance is located. In this example, the --auto-recovery-timeout
parameter is set to 5 minutes.
- To disable Auto-recovery for an EC2 instance, use the
modify-instance-metadata-options
command:
aws ec2 modify-instance-metadata-options --instance-id <INSTANCE_ID> --auto-recovery-enabled false --region <REGION>
Replace <INSTANCE_ID>
with the ID of the EC2 instance you want to disable Auto-recovery for, and <REGION>
with the AWS region where the instance is located.
That’s it! With Auto-recovery enabled, AWS will automatically attempt to recover your EC2 instance if it becomes impaired.