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.
ssh -i /path/to/your/key.pem firstname.lastname@example.org
Step 2 - Switch User
You will need to switch to Super User.
Step 3 - GET Request
Once you are a Super User, run the
curl command to request the top-level metadata on your instance.
You will get this response:
Step 4 - Going Deeper
Now that you're able to get the high-level metadata information, you can an make more specialized requests such as:
Get public IP address.