What You Will Learn
Intermediate
- What User Data is and how it works
- How to create Launch Templates
- How to automate instance setup
User Data is a script that runs automatically when an EC2 instance starts for the first time. Use it to install software, configure settings, and start services — without SSH.
User Data script (bash)bash
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo 'Hello from $(hostname)
' > /var/www/html/index.htmlA Launch Template saves all your EC2 settings (AMI, type, security group, User Data) as a reusable blueprint. Used by Auto Scaling Groups.
Practical Exercise
Create a Launch Template with Amazon Linux 2
Add the User Data script above
Launch an EC2 instance from the template
Wait 2 minutes, then access the public IP in your browser
See the "Hello from hostname" page — installed automatically!
Key Takeaways
- User Data = script that runs on first boot (install software, start services).
- Launch Template = reusable EC2 blueprint.
- User Data runs as root, no SSH needed.
- ASG uses Launch Templates to create new instances.
Comments
Comments
Post a Comment