2

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?!?

1 Answer 1

1

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .