We can set up a simple Apache web server on an EC2 instance at launch using EC2 user data as follows:
- Go to the EC2 dashboard and click on Instances from the left sidebar. Click on the Launch Instance button at the top of the page, select Amazon Linux 2 AMI, set Type to t2.micro, and click Next: Configure Instance Details.
- On the Configure Instance Details page, leave the Network, Subnet, and Auto-assign Public IP settings with their default values and scroll down to the Advanced Details section.
- In the User data textbox under the Advanced Details section, enter the following text:
#!/bin/bashsudo suyum update -yyum install -y httpd systemctl start httpd.service systemctl enable httpd.service
The Advanced Details section ...