The EC2 Instance Metadata Service (IMDS) is an instance-local HTTP service. An EC2 instance can query it for metadata and planned-action information without reaching an external endpoint. section 3.8.2
The service matters in two practical situations:
- Spot Instance interruption handling: query the planned-action endpoint to learn whether AWS has scheduled termination within two minutes. section 3.8.2
- Security: an attacker who reaches an EC2 machine can communicate with IMDS and authenticate as an AWS resource. section 5.3
Check for a planned Spot Instance action
From the instance, use Session Manager to run curl against http://169.254.169.254/latest/meta-data/spot/instance-action. A 404 response indicates that AWS has not marked the instance for termination; a response such as {"action": "stop", "time": "2022-04-08T12:12:00Z"} indicates a planned action. section 3.8.2
$ curl http://169.254.169.254/latest/meta-data/spot/instance-action
<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www .w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www .w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
</body>
</html>
sh-4.2$
Inspect the endpoint command and its 404 response. section 3.8.2

