Correct option:
Create a CloudWatch alarm for CPU Utilization of the Amazon EC2 instance, with detailed monitoring enabled. Configure an action to restart the instance when the alarm is triggered
CPUUtilization is an instance metric that is already defined with CloudWatch for monitoring Amazon EC2 instances.
By default, your instance is enabled for basic monitoring. You can optionally enable detailed monitoring. After you enable detailed monitoring, the Amazon EC2 console displays monitoring graphs with a 1-minute period for the instance. In Basic monitoring, data is available automatically in 5-minute periods at no charge. For Detailed monitoring, data is available in 1-minute periods for an additional charge.
If you enable detailed monitoring, you are charged per metric that is sent to CloudWatch. You are not charged for data storage.
You can enable detailed monitoring on an instance as you launch it or after the instance is running or stopped. Enabling detailed monitoring on an instance does not affect the monitoring of the EBS volumes attached to the instance.
Once the detailed monitoring is active, you can configure an action to restart the instance when the alarm is triggered based on the CPUUtilization metric.
Steps to enable detailed monitoring on the instance:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html
Incorrect options:
CPU utilization parameter of an Amazon EC2 instance is a pre-defined metric in CloudWatch and is available in basic monitoring of an instance. Configure the restart action against this metric to automate the instance restart process - In Basic monitoring, data is available at 5-minute periods. Since the customer wants an immediate restart, basic monitoring is not the right choice here.
Create a custom code to send CPU utilization of the instance to CloudWatch metrics. Configure an action to restart the instance when the alarm is triggered - Custom code is not needed since CPU utilization is a pre-defined metric that CloudWatch can track for Amazon EC2 instances.
Create a CloudWatch alarm for CPU Utilization of the Amazon EC2 instance, with basic monitoring enabled. Configure an AWS Lambda function against the alarm action. The Lambda function will restart the instance, automating the process - Instance restart is a configurable item for an action when an alarm is triggered. This is a straightforward way compared to using Lambda functions.
References:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html