我想要检索托管通过我的 CFT 创建的 Apache Solr 应用程序的 EC2 实例的 IP 地址及其运行的端口号。我需要将此信息传递给另一个堆栈。有什么办法可以做到这一点吗?
最佳答案
通常这是通过 CloudFormation 输出完成的: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html
语法如下所示:
"Outputs" : {
"Logical ID" : {
"Description" : "Information about the value",
"Value" : "Value to return",
"Export" : {
"Name" : "Value to export"
}
}
}
或者举个例子: 这里我们定义一个简单的EC2实例
"Server" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
}
}
在这个语句中,我们公开了实例的公共(public) ip 属性。
"Outputs" : {
"PublicIp" : {
"Value" : { "Fn::GetAtt" : [ "Server", "PublicIp" ]},
"Description" : "Server's PublicIp Address"
}
}
(从本期获得的示例:AWS CloudFormation: How to output a machine's PublicIP? 信用应归于:Matt Houser)
默认情况下,Solr 在端口:8983 上运行,因此除非情况并非如此,否则可能可以使用它。
在这种情况下,您的输出可能如下所示:
"Outputs" : {
"PublicIp" : {
"Value" : { "Fn::GetAtt" : [ "Server", "PublicIp" ]},
"Description" : "Server's PublicIp Address"
},
"SolrPort" : {
"Value" : "8983",
"Description" : "Port that Solr is running on."
}
}
关于amazon-web-services - 检索通过 CFT 创建的 EC2 托管 Apache 应用程序的 IP 地址和端口号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58728707/