Ec2 public-hostname on instance reload

I need to get the public hostname to start the service on reboot. When I use "ec2-metadata", I don't get information when I put a call to @reboot in crontab. So how should I solve this problem? Thanks.

+4
source share
5 answers

You may need to wait a bit before the hostname becomes available after a reboot. Therefore, either run the ec2-metadata command later in the boot sequence after the network interfaces stabilize, or hibernate until it returns something useful

0
source

The correct solution is not to use cron, but to place the script in the file / etc / profile.d

0
source

Assuming Ubuntu for OS.

I would try connecting it to the network manager launch event.

0
source

You can create a shell script using this command

publicdns=$(curl http://169.254.169.254/latest/meta-data/public-hostname) 

This will store your public ec2 computer name inside the $ publicdns variable. Then you can also run the script with all the commands you need to run. Schedule a script to run @reboot with cron.

0
source

In the terminal, enter this to get the public IP address

 curl ifconfig.me 
0
source

All Articles