AWS CloudFormation:如何输出机器的PublicIP? [英] AWS CloudFormation: How to output a machine's PublicIP?

查看:55
本文介绍了AWS CloudFormation:如何输出机器的PublicIP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个CloudFormation模板,该模板创建了一个Linux docker主机。

I wrote a CloudFormation template which creates a linux docker host.

我想在输出部分下显示计算机的PublicIP。

I want to display the PublicIP of the machine under the "Outputs" section.

这是模板的相关部分:

"Outputs" : {
    "ServerAddress" : {
      "Value" : { "Fn::GetAtt" : [ "Server", "PublicDnsName" ] },
      "Description" : "Server Domain Name"
    },
    "SecurityGroup" : {
      "Value" : { "Fn::GetAtt" : [ "ServerSecurityGroup", "GroupId" ] },
      "Description" : "Server Security Group Id"
    },
    "PublicIp" : {
      "Value" : { "Fn::GetAtt" : [ "ServerPublicIp", "PublicIp" ]},
      "Description" : "Server's PublicIp Address"
    },
  }

I已阅读 AWS官方文档关于使用 Fn :: GetAtt并尝试在模板中实现它,但是当我尝试创建堆栈时,出现以下错误:

I've read in the official AWS documentation about using "Fn::GetAtt" and tried to implement it in my template, but when I try to create the stack I get the following error:

Error
Template validation error: Template error: instance of Fn::GetAtt references undefined resource ServerPublicIp

据我了解,GetAtt行的第一部分是LogicalName(我可以选择吗?),第二部分是上面链接中显示的real属性。

As far as I understand, the first part in the GetAtt line is a LogicalName (which I can choose?) and the second one is the real attribute as appears on the above link.

所以我的问题是如何在输出部分下显示服务器的PublicIP?

So my question is how to display the PublicIP of the server under the Outputs section?

推荐答案

假设您的模板中有一个名为 Server 的EC2实例资源:

Assuming your have an EC2 instance resource in your template named Server:

"Server" : {
    "Type" : "AWS::EC2::Instance",
    "Properties" : {
    }
}

您输出引用其资源名称的公共IP地址:

You output the public IP address referencing it's resource name:

"Outputs" : {
    "PublicIp" : {
      "Value" : { "Fn::GetAtt" : [ "Server", "PublicIp" ]},
      "Description" : "Server's PublicIp Address"
    }
}

这篇关于AWS CloudFormation:如何输出机器的PublicIP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆