Using Windows server 2016 instances.
I want the instance to run a local command before it terminates.
I can have a script run when windows is shutting down.
I would like the script to check if the instance itself is in the terminating state and if so run some clean up stuff.
Not sure from the docs, is there a way to check if the local instance is being terminated from the instance itself? https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-categories
This returns InstanceStatuses:
aws ec2 describe-instance-status --include-all-instances --instance-ids i-123123123
Which looks like:
{
"InstanceStatuses": [
{
"AvailabilityZone": "us-west-2a",
"InstanceId": "i-123123123",
"InstanceState": {
"Code": 16,
"Name": "running"
},
"InstanceStatus": {
"Details": [
{
"Name": "reachability",
"Status": "passed"
}
],
"Status": "ok"
},
"SystemStatus": {
"Details": [
{
"Name": "reachability",
"Status": "passed"
}
],
"Status": "ok"
}
}
]
}
What does the state looks like when the instance is "terminating"? Not already terminated but pending termination? How can I check if an instance is in the pending termination state?