If you stop the EC2 instance externally (for example, by the AWS CLI or AWS Management Console), Windows may not shutdown gracefully. If this happens, you will b prompted on first RDP afterwards.
During the EC2 instance stop process:
The AWS infrastructure notifies the EC2 instance to shutdown, then
The agent running on the EC2 instance catches the notification and initiates the shutdown.
If the above sequence does not happen within 4 minutes of the stop command, AWS will forcefully stop the EC2 instance "ungracefully".
Possible Problem 1: AWS does not notify the EC2 instance to shutdown
There have been cases with the new T3, M5, C5, and R5 EC2 instance types where the hardware does not notify the EC2 instance to stop.
I witnessed this issue myself in early March 2018 in us-east-1. Today (late March 2018) it appears to be fixed in us-east-1.
If you're using an T3, M5, C5 or R5 instance type, see our article here: Fixing Windows Shutdown and Reboot Problems on Nitro Instances
Possible Problem 2: On older EC2 instance types, the agent does not process the signal
Older EC2 instance types signalled the "AWS Lite Guest Agent'" running on the EC2 instance to shutdown the instance.
If the agent on the EC2 instance is not installed, was not started, or otherwise is not running, then the EC2 instance will not be shutdown properly.
Some customers have expressed that updates to the PV drivers and/or AWS LiteAgent have affected this.
Possible Problem 3: On newer EC2 instance types, Windows does not know what to do
Newer EC2 instance types, such as the M5, C5, and H1 families, issue an 'ACPI' power button push. Normally, Windows would intercept this and shutdown the OS.
Run 'powercfg.cpl' and click "Choose what the power buttons do" link on the left to ensure Windows is configured to shutdown when the power button is pressed.
Possible Problem 4: Custom software installed on the EC2 instance is blocking a graceful shutdown
If you have confirmed that problems 1 and 2 are not occurring, then the final place to look is the software installed on the EC2 instance. It's very likely that some software is not allowing Windows to shutdown within the 4 minute time limit.
To resolve this, you will need to diagnose the software installed on your EC2 instance.
There is no way to change the "4 minute time limit".
If you want to disable this prompt, you can do so in the Windows Group Policy editor:
However, doing so will also eliminate the prompt in case of a true unexpected shutdown.