在其他 EC2 实例的配置文件中使用 1 个 EC2 实例的 IP

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

我是 Cloud Formation 的新手。 我需要一点帮助。我使用 .yaml 文件创建了 2 个 EC2 实例。一个是我的数据库实例,另一个是我的 Web 实例。现在我必须在我的 Web 实例的配置文件中提供我的数据库实例的 IP。 怎么做到的?

您可以使用 !GetAtt db-instance.PrivateIp 引用 EC2 实例的私有 IP 地址(其中 db-instance 是 YAML 模板中该实例的节点名称(在定义的顶层).

参见:AWS::EC2::Instance - Return Values