User Data is a feature of EC2 that allows you to pass a shell script or cloud-init directive to an instance at launch time. The script runs automatically as root during the first boot, enabling fully automated instance configuration without any manual login.
User Data is the primary mechanism for bootstrapping EC2 instances. It is passed to the instance at launch via the instance metadata service and executed once by cloud-init during the first boot cycle. User Data is the foundation of auto-scaling automation — every new instance spun up by an Auto Scaling Group can configure itself using User Data.
Runs only ONCE by default — on the very first boot after launch
Executed as the root user — no sudo needed inside the script
Maximum size is 16 KB — for larger scripts, use S3 and download from User Data
Base64-encoded internally by AWS — the Console and CLI handle encoding automatically
Accessible at the metadata URL: http://169.254.169.254/latest/user-data
Can be a shell script (#!/bin/bash) or cloud-init YAML format
You can modify User Data while the instance is stopped and re-run it on next boot
Logs for User Data execution are found at /var/log/cloud-init-output.log on the instance