Which solutions will meet this requirement?
(Choose two.)
Install the Amazon CloudWatch agent on the EC2 instances. Configure the CloudWatch agent to monitor the service. Set the CloudWatch action to restart if the service health check fails.
Tag the EC2 instances. Create an AWS Lambda function that uses AWS Systems Manager Session Manager to log in to the tagged EC2 instances and restart the service. Schedule the Lambda function to run every 5 minutes.
Tag the EC2 instances. Use AWS Systems Manager State Manager to create an association that uses the AWS-RunShellScript document. Configure the association command with a script that checks if the service is running and that starts the service if the service is not running. For targets, specify the EC2 instance tag. Schedule the association to run every 5 minutes.
Update the EC2 user data that is specified in the Auto Scaling group’s launch template to include a script that runs on a cron schedule every 5 minutes. Configure the script to check if the service is running and to start the service if the service is not running. Redeploy all the EC2 instances in the Auto Scaling group with the updated launch template.
Update the EC2 user data that is specified in the Auto Scaling group’s launch template to ensure that the service runs during startup. Redeploy all the EC2 instances in the Auto Scaling group with the updated launch template.
Explanations:
Installing the Amazon CloudWatch agent on the EC2 instances allows monitoring of the service. By configuring the agent to take action when a health check fails, such as restarting the service, the solution provides an automated recovery mechanism that responds to service crashes.
Although tagging the EC2 instances and creating a Lambda function can initiate a restart of the service, it does not provide real-time monitoring. The function would only execute every 5 minutes, potentially leaving the service down during that period. This does not ensure immediate recovery from crashes.
Using AWS Systems Manager State Manager to create an association that checks the service status and restarts it if necessary is a viable solution. This approach leverages Systems Manager to regularly monitor and recover the service automatically on all tagged EC2 instances, thereby providing effective automation.
Updating user data to run a cron job every 5 minutes could lead to unnecessary resource consumption and complexity. Additionally, using cron for monitoring and restarting services is not the best practice in AWS, as it does not provide immediate recovery upon failure and is less efficient than other solutions.
Updating user data to ensure the service runs during startup addresses only the initial launch of the service. It does not provide a solution for handling service crashes after startup, making it ineffective for automating recovery from unexpected failures.