我写了一个创建Linux docker主机的CloudFormation模板。
我想在"输出"下显示机器的PublicIP。部分。
这是模板的相关部分:
"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"
},
}
我已在official AWS documentation中读到关于使用" Fn :: GetAtt"并尝试在我的模板中实现它,但当我尝试创建堆栈时,我收到以下错误:
Error
Template validation error: Template error: instance of Fn::GetAtt references undefined resource ServerPublicIp
据我所知,GetAtt系列的第一部分是LogicalName(我可以选择?),第二部分是上面链接中显示的真实属性。
所以我的问题是如何在Outputs部分下显示服务器的PublicIP?
答案 0 :(得分:11)
假设您的模板中有一个名为<table class="mGrid">
<thead>
<tr class="hdr">
<th><a href="http://google.com">Nº Despesa</a></th>
<th><a href="http://google.com">Consultor</a></th>
<th><a href="http://google.com">Setor</a></th>
<th><a href="http://google.com">Empresa</a></th>
<th><a href="http://google.com">Motivo</a></th>
<th><a href="http://google.com">Data</a></th>
<th><a href="http://google.com">Hotel</a></th>
<th><a href="http://google.com">Refeição</a></th>
<th><a href="http://google.com">Veículo</a></th>
<th><a href="http://google.com">Taxi</a></th>
<th><a href="http://google.com">Outros</a></th>
<th>Vlr Total</th>
<th>Comprovantes OK</th>
<th>Aprovado</th>
<th>Status Visita</th>
</tr>
</thead>
<tbody>
<tr class="nrm">
<td><span>00392-05-01</span></td>
<td><span>Names na</span></td>
<td><span>Plantão 24x7</span></td>
<td><span>Empres</span></td>
<td><span>Serviço</span></td>
<td><span>06-03-2017</span></td>
<td><span>Não</span></td>
<td><span>R$ 80,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 150,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 230,00</span></td>
<td><span>Sim</span></td>
<td><span>Sim</span></td>
<td><span>Liquidado</span></td>
</tr>
<tr class="alt">
<td><span>00392-03-01</span></td>
<td><span>Names Names Names</span></td>
<td><span>Plantão 24x7</span></td>
<td><span>EMPR</span></td>
<td><span>Serviço</span></td>
<td><span>31-01-2017</span></td>
<td><span>Não</span></td>
<td><span>R$ 80,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 100,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 180,00</span></td>
<td><span>Sim</span></td>
<td><span>Sim</span></td>
<td><span>Liquidado</span></td>
</tr>
<tr class="nrm">
<td><span>00392-02-01</span></td>
<td><span>Names na Names Namesnam</span></td>
<td><span>Plantão 24x7</span></td>
<td><span>Empres</span></td>
<td><span>Serviço</span></td>
<td><span>31-01-2017</span></td>
<td><span>Sim</span></td>
<td><span>R$ 80,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 100,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 180,00</span></td>
<td><span>Sim</span></td>
<td><span>Sim</span></td>
<td><span>Liquidado</span></td>
</tr>
<tr class="alt">
<td><span>00392-01-02</span></td>
<td><span>Names na Names Namesnam</span></td>
<td><span>Plantão 24x7</span></td>
<td><span>EMPR</span></td>
<td><span>Relacionamentos</span></td>
<td><span>31-01-2017</span></td>
<td><span>Não</span></td>
<td><span>R$ 30,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 100,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 130,00</span></td>
<td><span>Sim</span></td>
<td><span>Sim</span></td>
<td><span>Liquidado</span></td>
</tr>
<tr class="nrm">
<td><span>00392-01-01</span></td>
<td><span>Names na Names</span></td>
<td><span>Plantão 24x7</span></td>
<td><span>EMPR</span></td>
<td><span>Relacionamentos</span></td>
<td><span>30-01-2017</span></td>
<td><span>Sim</span></td>
<td><span>R$ 80,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 100,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 180,00</span></td>
<td><span>Sim</span></td>
<td><span>Sim</span></td>
<td><span>Liquidado</span></td>
</tr>
<tr class="alt">
<td><span>00388-01-01</span></td>
<td><span>Names na Namesnam</span></td>
<td><span>Requisitos</span></td>
<td><span>Empres</span></td>
<td><span>Serviço</span></td>
<td><span>01-02-2017</span></td>
<td><span>Não</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 246,60</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 246,60</span></td>
<td><span>Sim</span></td>
<td><span>Sim</span></td>
<td><span>Liquidado</span></td>
</tr>
<tr class="nrm">
<td><span>00387-02-01</span></td>
<td><span>Names na Names Namesnam</span></td>
<td><span>Middleware</span></td>
<td><span>Empresa Empresaempr EMPR-ESA</span></td>
<td><span>Serviço</span></td>
<td><span>26-01-2017</span></td>
<td><span>Não</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 266,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 266,00</span></td>
<td><span>Sim</span></td>
<td><span>Sim</span></td>
<td><span>Liquidado</span></td>
</tr>
<tr class="alt">
<td><span>00387-01-01</span></td>
<td><span>Names na Names Namesnam</span></td>
<td><span>Middleware</span></td>
<td><span>Empres</span></td>
<td><span>Vendas</span></td>
<td><span>25-01-2017</span></td>
<td><span>Não</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 185,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 0,00</span></td>
<td><span>R$ 185,00</span></td>
<td><span>Sim</span></td>
<td><span>Sim</span></td>
<td><span>Liquidado</span></td>
</tr>
</tbody>
<tfoot>
<tr class="pgr">
<td colspan="16">
<table>
<tbody>
<tr>
<td><span>1</span></td>
<td><a href="http://google.com">2</a></td>
<td><a href="http://google.com">3</a></td>
<td><a href="http://google.com">4</a></td>
<td><a href="http://google.com">5</a></td>
<td><a href="http://google.com">6</a></td>
<td><a href="http://google.com">7</a></td>
<td><a href="http://google.com">8</a></td>
<td><a href="http://google.com">9</a></td>
<td><a href="http://google.com">10</a></td>
<td><a href="http://google.com">...</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tfoot>
</table>
的EC2实例资源:
Server
输出引用其资源名称的公共IP地址:
"Server" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
}
}
答案 1 :(得分:2)
如docs中所述,可以选择输出输出以进行跨栈引用。如果这是您的用例:
JSON:
"Outputs" : {
"PublicIp" : {
"Value" : { "Fn::GetAtt" : ["Server", "PublicIp"]},
"Description" : "Server Public IP"
"Export" : {
"Name" : {"Fn::Sub": "${AWS::StackName}-PublicIP"}
}
}
}
YAML:
Outputs:
PublicIp:
Description: Server Public IP
Value: !GetAtt Server.PublicIp
Export:
Name: !Sub "${AWS::StackName}-PublicIp"
另请参阅: