How it works
EC2 user data lets you provide initialization instructions when launching an instance. On supported Linux images, cloud-init can run a shell script or process cloud-init directives during startup. User data scripts normally run as root on the first boot, though the configuration can be changed. Successful setup still depends on the image, networking, permissions, and the script itself.
When to use it
Install updates and software or download files automatically at first launch.
Real-world example
A team supplies a user data script on a Linux web instance to install a web server and retrieve application files. It tests the script and network access before using the same configuration for instances launched by Auto Scaling.
Key facts
- By default, runs on the first boot; it can be configured to run again.
- On Linux, user data scripts run as root.
Common pitfall
Do not put plaintext passwords or API secrets in user data. Principals with sufficient EC2 permissions or access to instance metadata may retrieve it. Obtain secrets at runtime using a narrowly scoped instance role.
Often confused with
EC2 Instance Connect, which opens a session rather than configuring the instance at boot.
References
Prepared by Cloud Quest. Check current behavior and limits in the AWS documentation:
Keywords you will see in SAA-C03 questions
- install at boot
Understand it for real with 3D models and simulated labs
Connect the concept to a working architecture.