I understand that your Lightsail instance keeps failing System checks now and then. After that, you have to manually stop and start your instance to migrate it to a new host. However, you would like to automate the process of stopping and starting your instance in the case where System failure happens.
I suggest you look at your system logs to check what is causing your Lightsail instances to have System check failure. The logs will reveal an error that can help you troubleshoot the issue.
To automatically stop and start your instance you can use a Lambda function and CloudWatch Events to trigger these actions. CloudWatch automatically manages a variety of metrics for standard EC2 instances, however, the metrics collected in Lightsail are by default not visible in the CloudWatch dashboard. With that being said, you will have to do the following to get your Lightsail metrics in CloudWatch:
- Create an IAM user with the necessary permissions to submit the CloudWatch metrics data collected from the Lightsail instance.
- Installing the CloudWatch Agent on your Lightsail.
- Configuring the CloudWatch Agent to use the IAM user when submitting data to CloudWatch
Below is a sample code you can use to schedule the stop of the Instance:
import boto3 region = 'us-west-1' client = boto3.client('lightsail', region_name='region') def lambda_handler(event, context): client.stop_instance( instanceId='ID-OF-YOUR-LIGHTSAIL-INSTANCE')
A sample code you can use to schedule the start of the Instance:
import boto3 region = 'us-west-1' client = boto3.client('lightsail', region_name='region') def lambda_handler(event, context): client.start_instance( instanceId='ID-OF-YOUR-LIGHTSAIL-INSTANCE')
For region, replace "us-west-1" with the AWS Region that your instance is in and replace 'ID-OF-YOUR-LIGHTSAIL-INSTANCE' with the ID of the specific instance that you want to stop and start.
I hope that this information will be helpful.
EC2 instance shows status check fail during couple out instances.Accepted Answerasked 4 years ago
Multiple system check failures over past 18 months - how to automatically stop/start instance?asked 10 months ago
A LightSail instance has stuck in Pending transition for 4 months.Accepted Answerasked 6 months ago
Impossible to connect to Windows Lightsail instanceasked 2 months ago
Free 12 months AWS but Lightsail paid?asked 4 months ago
Instance reachability check failedasked 2 months ago
Windows instance takes ~18 minutes to restartasked a year ago
torque service exits with status 3 on master nodeasked 2 years ago
Status check fails if ec2 is changed to the past dateasked 4 years ago
System reachability check passed Instance reachability failed!asked 4 years ago