What Is an Instance Metadata Service? Safely Query Cloud Details from a VM
An Instance Metadata Service (IMDS) is a provider-specific local API that lets software inside a virtual machine (VM) read details about that VM, such as its identity, network, or placement.
An Instance Metadata Service (IMDS) is a provider-specific local API that lets software inside a virtual machine (VM) read details about that VM, such as its identity, network, or placement. Some clouds also use it to issue managed identity tokens. It is useful for application configuration, but providers do not share one endpoint, authentication method, or response schema. Because metadata endpoints can also expose workload credentials, treat access as a security boundary rather than an ordinary web API.
What is instance metadata used for?
When a cloud control plane creates a VM, it knows facts such as the instance ID, region, availability zone, network addresses, and machine type. The metadata service lets code in the guest operating system read selected facts. An application might add the instance ID to logs, select region-specific settings, or place replicas across fault domains. Azure IMDS also exposes scheduled events and managed identity tokens; EC2 IMDS can provide instance metadata and temporary credentials for an attached IAM role.
The service is generally available at a link-local address reachable from inside the VM. AWS and Azure document the IPv4 address 169.254.169.254; Google Compute Engine documents metadata.google.internal and the same IPv4 address. A shared address does not mean a shared API: paths, required headers, version parameters, and token flows differ. Each example below works only on a VM in that provider.
Also distinguish metadata from user data. Metadata is information the platform exposes about a VM. User data can be input supplied by an operator during provisioning. Some providers expose user data through a metadata interface, but its security, lifetime, and update behavior are different. Do not use metadata or user data as a store for passwords or long-lived API keys.
How do AWS, Azure, and Google Cloud differ?
Each provider offers a local HTTP endpoint, but uses different request details to identify an intentional metadata request.
| Provider | Example endpoint | Example request requirement |
|---|---|---|
| Amazon EC2 | http://169.254.169.254/latest/meta-data/ | With IMDSv2, first obtain a session token with a PUT request, then send it in a header on metadata GET requests. An instance can be configured to require IMDSv2. |
| Azure VM | http://169.254.169.254/metadata/instance | Include Metadata: true and an api-version; bypass proxies and do not send X-Forwarded-For. |
| Google Compute Engine | http://metadata.google.internal/computeMetadata/v1/ | Include the Metadata-Flavor: Google header. The server is accessed from within the instance. |
These differences explain why a copied request may fail on another cloud. A shared library should keep URL, headers, and API versions in provider-specific adapters, and fail safely when data is absent. Check provider documentation for field availability and version instead of assuming a region or name always exists.
How can you query metadata from a VM?
The following are read-only examples to run inside the respective provider's VM. They do not query a VM when run from a local development computer.
On Amazon EC2, obtain an IMDSv2 token and request the instance ID:
TOKEN=$(curl -sS -X PUT 'http://169.254.169.254/latest/api/token' \
-H 'X-aws-ec2-metadata-token-ttl-seconds: 21600')
curl -sS -H "X-aws-ec2-metadata-token: $TOKEN" \
'http://169.254.169.254/latest/meta-data/instance-id'On an Azure VM, request instance metadata as JSON with an explicit API version:
curl --noproxy '*' -sS \
-H 'Metadata: true' \
'http://169.254.169.254/metadata/instance?api-version=2025-04-07' | jqOn Google Compute Engine, request the project ID:
curl -sS -H 'Metadata-Flavor: Google' \
'http://metadata.google.internal/computeMetadata/v1/project/project-id'On success, the examples return an instance ID, JSON metadata, and a project ID respectively. These values belong to the actual VM and project, so do not compare them to a value copied from another instance. The commands illustrate documented request shapes; they were not run against cloud VMs for this article.
How should metadata access be protected?
Do not assume metadata contains only public information. AWS instance-role credentials and Azure managed identity tokens are examples of authorization material that may be available through these services. A server-side request forgery (SSRF) flaw or open proxy in an application could be abused to send requests to the endpoint from the VM's network context.
Reduce exposure with these practices:
On EC2, confirm that the application and SDK support IMDSv2, then configure the instance to require tokens. In containers, the response hop limit can affect token delivery, so test the real network path.
Grant the VM only the permissions it needs. Never expose metadata-derived tokens or temporary credentials in logs, error responses, or browser output.
Restrict arbitrary URL fetching, redirects, and proxy behavior in applications, and apply SSRF defenses. Host firewall rules can further limit access to known processes, but test them so they do not break platform agents.
On Azure, use the documented required header and bypass proxy settings. `Metadata: true` marks an intended metadata request; it does not provide per-process authentication or access control within the VM.
Request only the fields you need instead of polling frequently. Use bounded retries and handle missing values explicitly.
IMDSv2 is one AWS defense layer; it does not fix an application's SSRF flaw or excessive instance permissions. Check current provider security settings and image/SDK compatibility together.
What should you check when a request fails?
First verify that the request runs inside the VM and uses the correct provider endpoint and path. Inspect the HTTP status and response. On AWS, check that IMDS is enabled, whether the instance requires IMDSv2, and whether the token PUT succeeded. If access fails only in a container, check its network path and hop limit. On Azure, verify Metadata: true, api-version, and proxy bypass. On Google Cloud, check whether metadata.google.internal resolves to 169.254.169.254 and whether Metadata-Flavor: Google is present.
Providers may throttle excessive requests, and transient errors or nonexistent paths can occur. Azure documents retry behavior for some response codes and version-dependent fields; Google recommends checking DNS resolution and metadata-server connectivity separately. Use a limited retry policy rather than looping indefinitely, define a fallback when required metadata is missing, and check whether a firewall change would disrupt platform services before applying it.
Sources
[AWS EC2: Use the Instance Metadata Service](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html)
[AWS EC2: Configure instance metadata options](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html)
[AWS Security Hub: EC2 exposures and IMDSv2 guidance](https://docs.aws.amazon.com/securityhub/latest/userguide/exposure-ec2-instance.html)
[Microsoft Learn: Azure Instance Metadata Service](https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service)
[Google Cloud: View and query VM metadata](https://docs.cloud.google.com/compute/docs/metadata/querying-metadata)
[Google Cloud: Troubleshoot metadata server access](https://docs.cloud.google.com/compute/docs/troubleshooting/troubleshoot-metadata-server)
Based on official AWS, Microsoft, and Google documentation reviewed on November 19, 2026. Endpoints, API versions, fields, and security defaults can change; verify the target VM type and current provider documentation before production use.