'how to fix startup script for aws ec2, to display hello world, other meta data from 169.254.169.254
I am setting up new EC2 instances, and I want to be able to see hello world, the AZ and the IP address displayed. It only shows the apache start page.
I have preloaded the code listed below in the user startup section of EC2, in the advanced details, user data, and have "added as text" clicked and selected.
I copied this text off of a training video from udemy, Ultimate AWS Certified Solutions Architect Associate 2019 by Stephane Maarek, Lesson 60, rt53 EC2 setup at approx the 1:11 mark.
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd.service
systemctl enable httpd.service
EC2_AVAIL_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
echo "<h1>Hello World From Rokkitt at $(hostname -f) in AZ $EC2_AVAIL_ZONE </h1> > /var/www/html/index.html
I am just getting the apache start page, not the hello world and user meta data info. thank you, I am just starting so I apologize for any mistakes
Solution 1:[1]
You aren’t closing your double quotes when echoing html into the index.html. Try the below.
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd.service
systemctl enable httpd.service
EC2_AVAIL_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
echo "<h1>Hello World From Rokkitt at at $(hostname -f) in AZ $EC2_AVAIL_ZONE </h1>" > /var/www/html/index.html
Solution 2:[2]
ok, thank you ...
after carefully looking, I missed the closing quote as stated above. thanks! also, I spent time making sure the index.html file was present with the cat command with the string /var/www/html/index.html and it showed me the contents of that file. thank you again!
also, I set up my nacl and security group and internet gateway IGW to allow icmp traffic so I could ping the instance as well.
thanks!
1082
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Preet Sangha |
Solution 2 | 1082E1984 |