Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We would like to create a template for a fairly standard stack in AWS. We need three layers.

  1. Layer: Elastic Load Balancer

  2. Layer: several web servers which are created / destroyed according to alarms triggered by the demand on the site

  3. Layer: a database server

Instances on Layer 2 should know the host name of the database instance. Ideally I would like to get hold of the private IP of the database instance and pass it through user-data to the web servers.

Fn::GetAtt does not support the private ip (only the public)

I suppose an alternative would be to build the stack and afterwards to set manually the db private ip. It does though make our setup a bit less clean. We would ideally like everything to be described in the template. (even if this involves running a script through user-data)

Any suggestions?

share|improve this question
    
docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/… is the correct link to the doc for GetAtt - and it does in fact support the Private IP (nowadays at least) – Dan Farrell Jul 7 '15 at 16:43

I do this now to add new nodes to my puppet master. For example, I grab the private IP of the puppet master instance in the UserData section of my new node:

"echo ", { "Fn::GetAtt" : [ "MasterOfPuppets", "PrivateIp" ] }, " ", 
         { "Fn::GetAtt" : [ "MasterOfPuppets", "PrivateDnsName" ] } ," puppet 
    >> /etc/hosts\n","\n",

See page 119 of the CloudFormation User guide.

Alternatively you could use the instance MetaData:

curl http://169.254.169.254/latest/meta-data/local-ipv4/
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.