Skip to content

Sumit's Blog

AWS Solutions Architect | DevOps Engineer | Red Hat Specialist | Former Web Developer

  • AWS
  • Kubernetes
  • Linux
  • Python
  • Magento2
  • Linux
  • WordPress
  • About Me
  • Contact Me
  • Home
  • AWS
AWS

πŸ“Œ What is User Data in AWS EC2?

September 9, 2025September 9, 2025 [email protected]

User Data is a set of commands or a script that you can provide when launching an EC2 instance.

This script runs automatically the first time the instance starts.

It’s commonly used for automating instance configuration like installing packages, updating software, or running initialization tasks.

πŸ› οΈ Key Points

  1. User Data executes as root user.
  2. By default, it runs only once at the first boot (though you can configure it to run at every restart).
  3. Supported script types:
    • Linux instances β†’ Shell script (bash)
    • Windows instances β†’ PowerShell or Batch script
  4. Common uses:
    • Install Apache/Nginx, Docker, or other software.
    • Update packages (apt update, yum update).
    • Write files (config files, HTML pages).
    • Create users or run custom commands.

πŸ“– Example 1: Linux User Data (Shell Script)

#!/bin/bash
# Update packages
sudo yum update -y

# Install Apache
sudo yum install -y httpd

# Start Apache
sudo systemctl start httpd
sudo systemctl enable httpd

# Add simple webpage
echo "<h1>Hello from EC2 User Data!</h1>" > /var/www/html/index.html

πŸ› οΈ Sample User Data Script (Linux – RHEL / Amazon Linux / CentOS)

#!/bin/bash
# Update the system
yum update -y

# Install Apache (httpd)
yum install httpd -y

# Enable and start Apache service
systemctl enable --now httpd

# Create a simple homepage
echo "Hello Apache" > /var/www/html/index.html

# Overwrite with a custom HTML page
echo "<html><h1>Apache Server provisioned by Sumit Bera using User Data</h1></html>" > /var/www/html/index.html

βœ… What this script does

  1. Updates system packages (yum update -y)
  2. Installs Apache web server (yum install httpd -y)
  3. Starts Apache and enables auto-start on reboot (systemctl enable --now httpd)
  4. Writes content into /var/www/html/index.html so that when you hit the EC2 Public IP in a browser, you see the message: β€œApache Server provisioned by Sumit Bera using User Data”

πŸ‘‰ To use it:

  • While launching EC2 β†’ go to Advanced Details β†’ User Data β†’ paste this script.
  • Once the instance boots, Apache will already be running and serving the custom page.

Related posts:-

What is EBS in AWS?What is Amazon EBS? Types of Elastic Block Store in AWS ExplainedWhat is EBS in A...

How to Create ELB in AWS with EC2 Instances in Different Availability Zones (Step-by-Step Guide)

Understanding Docker Networking Data Flow β€” Step by Step Guide

πŸ” AWS Identity and Access Management (IAM) in AWS

Total Page Visits: 4916 - Today Page Visits: 1

Related Posts

AWS

Understanding Docker Networking Data Flow β€” Step by Step Guide

May 28, 2026May 28, 2026 [email protected]
AWS

πŸš€ Managing Containers Using Docker 🐳

May 12, 2026May 12, 2026 [email protected]

Post navigation

Previous: What is EBS in AWS?What is Amazon EBS? Types of Elastic Block Store in AWS ExplainedWhat is EBS in AWS?
Next: What is Kubernetes?Explain in diagram.

Search in site

Categories

  • AWS (8)
  • Azure-AI (1)
  • Future Technology (16)
  • Indian Technology (4)
  • Kubernetes (11)
  • Linux (8)
  • Magento2 (14)
  • Python (2)
  • Tips & Tricks (1)
  • Uncategorized (6)
  • Wordpress (14)

My Advertisement

Adsence Ads

Tags

AWS storage services (2) Certified Kubernetes Administrator (2) CKA (5) Cloud Computing (4) Cloud Native (9) Containerization (2) Container Orchestration (2) Containers (4) DevOps (12) DevOps Engineer (2) DevOps Tutorial (2) Docker (4) GKE (2) Google Cloud (3) Infrastructure as Code (2) Kubeadm (3) Kubectl (5) kubectl Commands (3) Kubelet (2) Kubernetes (10) Kubernetes Administration (4) Kubernetes Cluster (3) Kubernetes Commands (3) kubernetes for beginners (2) Kubernetes Hands-On (2) Kubernetes Lab (2) Kubernetes Labels (3) kubernetes nodes (2) Kubernetes Pod (2) kubernetes pods (4) Kubernetes Scaling (2) Kubernetes Storage (2) kubernetes tutorial (10) Kubernetes YAML (3) linux (7) Mysql (1) NGINX (4) NGINX on Kubernetes (2) PersistentVolume (2) PHP Fatal Error (2) ReplicaSet (2) ReplicationController (2) Ubuntu (4) Ubuntu 22.04 (2) YAML (3)

Magento 2 Extensions

Archives

  • September 2026 (1)
  • August 2026 (7)
  • July 2026 (3)
  • June 2026 (1)
  • May 2026 (3)
  • April 2026 (4)
  • September 2025 (4)
  • January 2025 (2)
  • November 2024 (1)
  • September 2021 (1)
  • August 2021 (1)
  • December 2020 (1)
  • April 2020 (1)
  • March 2020 (2)
  • September 2019 (1)
  • July 2019 (4)
  • June 2019 (2)
  • May 2019 (3)
  • April 2019 (17)
  • March 2019 (11)
  • February 2019 (1)
  • August 2018 (7)
  • July 2018 (2)

Advertisement

Categories

  • AWS (8)
  • Azure-AI (1)
  • Future Technology (16)
  • Indian Technology (4)
  • Kubernetes (11)
  • Linux (8)
  • Magento2 (14)
  • Python (2)
  • Tips & Tricks (1)
  • Uncategorized (6)
  • Wordpress (14)

Magento 2 Extension

Google adds

About Me

i’m a web developer that specializes in Magento2

 

GET IN TOUCH

  • Kolkata,West Bengal INDIA
  • (+91) 9679840783
  • [email protected]
  • [email protected]

  1. reyhan davi on How to reset the post query and use Multi-Pass Loop in WordPressAugust 30, 2026

    terima kasih informasi nya berguna

  2. reyhan davi on Created a nested Loop inside the main Loop to display related posts based on tags in WordPress.August 30, 2026

    thanks a lot of information greatfull

  1. reyhan davi on How to reset the post query and use Multi-Pass Loop in WordPressAugust 30, 2026

    terima kasih informasi nya berguna

  2. reyhan davi on Created a nested Loop inside the main Loop to display related posts based on tags in WordPress.August 30, 2026

    thanks a lot of information greatfull

      All Rights Reserved 2021.
      Proudly powered by WordPress | Theme: Fairy Blog by Candid Themes.