阅读背景:

AWS CloudFormation YAML - 引用在同一堆栈中创建的实例的私有IP,以写入配置文件

来源:互联网 

All,

所有,

I am trying to reference an instance's private IP that is created in the same stack this configuration file is written. The instance is called "instance" and according to AWS documentation found here I should be able to reference the private IP by using the below formatting.

我试图引用一个实例的私有IP,该私有IP是在写入此配置文件的同一堆栈中创建的。该实例称为“实例”,根据此处的AWS文档,我应该能够使用以下格式引用私有IP。

When I build the stack everything completes successfully but the log file literally has "!GetAtt instance.PrivateIp Example text here" written in it rather than the private IP. I tried using ${instance.PrivateIp} which did not work because it created a circular reference in the stack.

当我构建堆栈时,一切都成功完成,但日志文件字面上写有“!GetAtt instance.PrivateIp示例文本”,而不是私有IP。我尝试使用$ {instance.PrivateIp},它不起作用,因为它在堆栈中创建了一个循环引用。

Is there some other way that I should be referencing the private IP of this instance?

是否还有其他方法可以引用此实例的私有IP?

Thanks!

谢谢!

# Write config file
cat << EOF > /config.conf
!GetAtt instance.PrivateIp ${String1}
EOF

Edit: Looks like it can't be done because CFN is trying to query the resource that is in the process of creating. Hope this questions helps others that attempt to the same thing that I did here.

编辑:看起来无法完成,因为CFN正在尝试查询正在创建的资源。希望这些问题有助于其他尝试与我在这里做同样事情的人。

2 个解决方案

#1


0  

The parser should try to substitute text after it sees the "${" characters... Did you try ${instance.PrivateIp} ?

解析器在看到“$ {”字符后应尝试替换文本...您是否尝试过$ {instance.PrivateIp}?

#2


0  

Use this in your cloud-init script to query the private IP from the AWS metadata service:

在您的cloud-init脚本中使用它来从AWS元数据服务查询私有IP:

EC2_INSTANCE_ID=`wget -q -O - https://169.254.169.254/latest/meta-data/instance-id`

分享到: