How To Find An AWS EC2 Instance’s Public DNS Name From Within Itself
Have you ever found yourself stuck into a task on one of your AWS EC2 instances, probably having connected by IP, and wonder “what’s the public DNS for this thing?” Need to setup a friendly cname or register the instance with another part of your application? If only there was some way of getting this name without having stop what you’re currently doing, and especially without having to dig through the AWS web console trying to find it.
There’s actually an AWS endpoint you can query to find out about Instance Metadata, including a given instance’s public hostname.
In this snip, Josh will demonstrate how to use PowerShell to request this hostname from AWS using Invoke-WebRequest.
Prerequisites include: AWS Account Access to an AWS compute resource (e.g. EC2 or Lightsail)