This means you have used the private IP instead of the public IP.
The easiest way to solve this is to log in to the AWS Console for EC2 (https://console.aws.amazon.com/ec2). Then click on the instance and you can see it has both a public and a private DNS. You want to use the public one.
To get this information programmatically from an instance you can do this on the instance: curl -s http://169.254.169.254/2009-04-04/meta-data/public-hostname
. This is documented here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html