Unable to bootstrap EC2 server with user data

0

I am creating an AWS EC2 t2.micro and using the below user data. I added the condition to check for the presence of the "BootstrapCompleted " file and run updates AFTER that.


    #!/bin/bash
    while  [  ! -f /tmp/BootstrapCompleted ]
    do
      sleep 300
    done
    echo "file found" >> /tmp/ameya.log
    echo -e "Ameya is going mad" >> /tmp/ameya.log
    sleep 120
    yum update -y >> /tmp/ameya.log
    echo -e "\n My Sanity is restored" >> /tmp/ameya.log

However, when I do SSH to the VM and run

yum update -y

It runs the updates meaning they are not installed with User Data.

checked the log file

cat /var/log/cloud-init-output.log

I see some issue here. Last few lines output as below.

Cloud-init v. 22.1-5.el8 running 'modules:config' at Thu, 23 Feb 2023 01:59:01 +0000. Up 101.14 seconds.
Errors during downloading metadata for repository 'epel':
  - Curl error (6): Couldn't resolve host name for https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/repodata/repomd.xml [Could not resolve host: dl.fedoraproject.org]
Error: Failed to download metadata for repo 'epel': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
Cloud-init v. 22.1-5.el8 running 'modules:final' at Thu, 23 Feb 2023 02:00:10 +0000. Up 170.00 seconds.
Cloud-init v. 22.1-5.el8 finished at Thu, 23 Feb 2023 02:02:12 +0000. Datasource DataSourceEc2Local.  Up 291.76 seconds

I note that ameya.log is created as per below.

[root@ANL62600251 ~]# cat /tmp/ameya.log 
file found
Ameya is going mad
Extra Packages for Enterprise Linux 8 - x86_64  0.0  B/s |   0  B     00:00    

 My Sanity is restored

I now run

yum update

Interesting observation is

yum update
Extra Packages for Enterprise Linux 8 - x86_64                                                          6.5 kB/s | 4.7 kB     00:00    

This tells me that, when yum update was running it had no internet connection?

asked a year ago237 views
1 Answer
0

Hello, Greetings of the day!! Thank you for contacting AWS.

I understand you are getting the following error while installing updates on your EC2 instance via user-data script a stack

"Error: Failed to download metadata for repo 'epel': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried",

However, the updates are getting installed successfully while connecting to the instance via SSH. You believe that this could be an issue with internet connectivity during the execution of user-data script.

As per the details mentioned in your query, it seems that this could occur due to either DNS resolution issue or lack of internet connectivity. However, to better address the issue, we require details that are non-public information. Thus, I request you to kindly open a support case with AWS using the following link https://console.aws.amazon.com/support/home#/case/create

Thank you and have a nice day!!

AWS
SUPPORT ENGINEER
Aditi_B
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions