Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using an elastic ip in a CloudFormation template

"ServerEIP" : {
 "Type" : "AWS::EC2::EIP",
 "Properties" : {
 }
},

Later on I have an EC2 Instance

"Server" : {
  "Type" : "AWS::EC2::Instance",
  ...

Because I want to make the IP Address of multiple instances known between each other, see here, I am using EIPAssociation to actually bind the Elastic IP to the EC2 instance:

"ServerIPAssoc" : {
     "Type" : "AWS::EC2::EIPAssociation",
     "Properties" : {
         "InstanceId" : { "Ref" : "Server" },
         "EIP" : { "Ref" : "ServerEIP" }
     }
 },

Now in my startup script on the instance which runs as init.d-script, I am reading the "public hostname" of the instance:

PUBLIC_HOSTNAME=`curl http://169.254.169.254/latest/meta-data/public-hostname`

Now what happens here is that I initially seem to receive an incorrect hostname! Most likely the one for the initial public ip address that is assigned to the EC2 instance before the ElasticIP association takes place!

I already tried to put in some wait to let the public hostname settle, but it didn't have an effect when the sleep was not overly long (i.e. below 30 seconds).

Is there any other way I can ensure that I get the "public hostname" from the elastic ip address and not the one that is thrown away?!?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

In the end I used a few seconds delay during startup to allow the actual ip/hostname to settle before making the REST call during startup!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.