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

AWS EC2 User Data and Metadata Service

Use user data scripts for instance initialization and query the EC2 metadata service for instance information.

AWS EC2 User Data and Metadata Service

You'll learn how to automatically configure EC2 instances at launch and retrieve instance information programmatically.

What is User Data?

User data is a script or configuration you provide when launching an EC2 instance. It runs automatically once during the instance's first boot, making it perfect for initial setup tasks. Think of it like giving a new employee a "first day checklist"—install software, configure settings, download files, or set environment variables.

User data scripts are typically shell scripts (for Linux) or PowerShell scripts (for Windows). They execute with root/administrator privileges, so they can perform system-level operations without interaction.

Common User Data Uses

  • Installing web servers or applications
  • Downloading code from repositories
  • Configuring system settings
  • Setting up monitoring agents

What is the Metadata Service?

The metadata service is a special HTTP endpoint available from inside your EC2 instance at http://169.254.169.254. It provides real-time information about the running instance—like its instance ID, instance type, availability zone, security groups, and public IP address.

Think of it as a mirror your instance can look into to learn about itself. Your application code can query this service to make decisions based on where it's running.

Common Metadata Uses

  • Retrieving instance identity for logging
  • Discovering which availability zone the instance is in
  • Getting network configuration details
  • Accessing IAM role credentials (securely)

Key Takeaway: User data automates instance initialization at launch time, while the metadata service lets running instances discover their own configuration and environment details—both are essential for building automated, self-configuring infrastructure.