How can these requirements be met?
Create an AWS Lambda script to restart any EC2 instances that shut down unexpectedly.
Create an Auto Scaling group for each EC2 instance that has a minimum and maximum size of 1.
Create a new t2.micro instance to monitor the cluster instances. Configure the t2.micro instance to issue an aws ec2 reboot-instances command upon failure.
Create an Amazon CloudWatch alarm for the StatusCheckFailed_System metric, and then configure an EC2 action to recover the instance.
Explanations:
While a Lambda script could be set up to restart EC2 instances, it would not guarantee that the instance maintains the same IP address. Additionally, managing instance recovery through a Lambda function adds unnecessary complexity when better solutions exist.
Creating an Auto Scaling group with a minimum and maximum size of 1 does provide some level of availability but does not ensure that the instance retains the same IP address upon recovery, as a new instance would be assigned a new IP.
Using a separate t2.micro instance to monitor the cluster and issuing reboot commands is not a robust solution. It also does not ensure that the recovering instance retains the same IP address, as rebooting an instance does not guarantee that it will maintain its Elastic IP.
Configuring a CloudWatch alarm for the StatusCheckFailed_System metric allows for automatic recovery of the instance. This method ensures that the same instance is recovered if it fails, and if the instance is associated with an Elastic IP address, it maintains the same IP after recovery.