Course contentsShow
← Cloud and Infrastructure
Lesson 86 of 2,9892. Compute FoundationsFree lesson

Instance Metadata Service

Accessing VM metadata from within the instance, common metadata attributes, and security considerations.

Instance Metadata Service

What you'll learn: How virtual machines can discover information about themselves without external configuration files.

What Is the Instance Metadata Service?

The Instance Metadata Service is a special internal API that runs inside every cloud environment, allowing your VM to query information about itself. Think of it like a VM asking, "Who am I? What's my configuration?" and getting immediate answers without needing to store or manage that information manually.

When your VM launches, it doesn't automatically "know" details like its instance type, networking configuration, or which region it's in. The metadata service provides this self-discovery mechanism through a simple HTTP endpoint accessible only from within the VM itself.

How It Works

From inside your VM, you make HTTP requests to a special IP address (typically 169.254.169.254) that returns metadata about that specific instance. This only works from within the VM—external systems cannot access another VM's metadata.

Common Metadata Attributes

  • Instance ID: Unique identifier for your VM
  • Instance Type: The instance family and size (e.g., "t2.micro")
  • Public and Private IP Addresses: Current network configuration
  • Security Groups: Firewall rules applied to your VM
  • Region and Availability Zone: Physical location information
  • AMI ID: Which image was used to launch this VM
  • User Data: Custom bootstrap scripts you provided at launch

Security Considerations

While incredibly useful, the metadata service can expose sensitive information. Older versions (v1) had no authentication, meaning any process on the VM could access all metadata. Newer versions (v2) require session tokens, limiting access from server-side request forgery attacks and unauthorized processes.

Key Takeaway: The Instance Metadata Service lets VMs discover their own configuration dynamically at runtime through an internal HTTP API, enabling self-aware and adaptable cloud applications—but requires proper security configuration to prevent unauthorized access.