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.
source share