Search code examples
amazon-web-servicesamazon-ec2outputuser-data

Using the IP of 1 EC2 instance in a configuration file of Other EC2 instance


I am new to Cloud Formation. I need a little help. I have created 2 EC2 instances using .yaml file. One is my database instance and other is my web instance. Now I have to give the IP of my database instance in a configuration file of my web instance. How can it be done?


Solution

  • You can refer to the private IP address of an EC2 instance using !GetAtt db-instance.PrivateIp (where db-instance is the node name of that instance in your YAML template (at the top-level of the definition).

    See: AWS::EC2::Instance - Return Values