I'm trying to pass user data to my EC2 instance at the time of creation using AWS CLI run-instances command.
I placed the below command in a file:
#!/bin/bash
sudo su
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
echo "<html><h1>Welcome to the server</h1><html>" >> /var/www/html/index.html
All the AWS CLI command I ran(with .txt and without):
aws ec2 run-instances --image-id ami-062f7200baf2fa504 --count 1 --instance-type t2.micro --key-name lab115key --security-groups my-sg --region us-east-1 --user-data file://./text1.txtaws ec2 run-instances --image-id ami-062f7200baf2fa504 --count 1 --instance-type t2.micro --key-name lab115key --security-groups my-sg --region us-east-1 --user-data file://./text1aws ec2 run-instances --image-id ami-062f7200baf2fa504 --count 1 --instance-type t2.micro --key-name lab115key --security-groups my-sg --region us-east-1 --user-data text1.txtaws ec2 run-instances --image-id ami-062f7200baf2fa504 --count 1 --instance-type t2.micro --key-name lab115key --security-groups my-sg --region us-east-1 --user-data text1
Then I tried to encode the script to Base64 still the User data is not accepted.
I created a Security group with port 80 and 22 with source 0.0.0.0/0 using Default VPC and Subnet.
AMI: Amazon Linux 2 - t2.micro
Region: us-east-1
ISSUE:
- HTTPD is not getting installed.
- index.html is not getting created in the path.
Am I doing something wrong? Why is it not working?
Any other way to solve this issue?
New Updates on this issue:
The User data that I passed to the run-instances command is getting installed but its taking too much of time.
Not all the time its getting installed. I ran the code five times, only 3 EC2 got User data installed.
From AWS Status Webpage: I found that us-east-1 Is having lots of latency issues.
/var/log/cloud-init-output.logto confirm that the script is being executed and to check for errors?