我想检索托管通过我的CFT创建的Apache Solr应用程序的EC2实例的IP地址及其运行的端口号。我需要将此信息传递给另一个堆栈。有什么办法可以做到吗?
huang346197 回答:检索通过CFT创建的托管Apache2 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","Description" : "Server's PublicIp Address"
},"SolrPort" : {
"Value" : "8983","Description" : "Port that Solr is running on."
}
}