Automatically get the DNS or IP address of a new EC2 instance.
As a web developer on EC2, there are times when I have to put on my DevOps hat and either write some Bash scripts or maybe use Ansible or Chef. It's not very often but common use cases include automating the process of starting a new EC2 instance, getting the DNS or IP address and adding it to either S3 or Route53. In these situations, the first thing I need to do is figure out where in the command line I will get that metadata. Here's how.
Step 1 - Log in
Log into your EC2 instance via ssh. In this example, I am using my Public DNS address but you can also use IPv4 Public IP.