gpt4 book ai didi

amazon-web-services - 使用 cloudformation (yaml) 在 Ubuntu 实例中启动 cfn-init

转载 作者:行者123 更新时间:2023-12-04 13:22:08 24 4
gpt4 key购买 nike

我尝试启动 cfn-init:

Fn::Base64: !Sub | 
#!/bin/bash
sudo apt-get -y install python-setuptools
mkdir aws-cfn-bootstrap-latest
curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
sudo easy_install aws-cfn-bootstrap-latest
sudo /usr/local/bin/cfn-init --stack !Ref 'AWS::StackName' --resource xxx --region !Ref 'AWS::Region'

第一步是有效的。我可以访问实例和 cfn-init已安装。当我执行cfn-init --stack..时当我对堆栈名称和区域的值进行硬编码时,我的 ec2 实例中的命令运行良好。

如何让它在 yaml 中工作脚本?似乎无法读取 StackName 和区域的值。

最佳答案

如果您使用 !Sub,则需要使用 ${} 包装变量,而不是使用 !Ref

试试这个

Fn::Base64: !Sub | 
#!/bin/bash
sudo apt-get -y install python-setuptools
mkdir aws-cfn-bootstrap-latest
curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
sudo easy_install aws-cfn-bootstrap-latest
sudo /usr/local/bin/cfn-init --stack ${AWS::StackName} --resource xxx --region ${AWS::Region}

If you specify template parameter names or resource logical IDs, such as ${InstanceTypeParameter}, AWS CloudFormation returns the same values as if you used the Ref intrinsic function. If you specify resource attributes, such as ${MyInstance.PublicIp}, AWS CloudFormation returns the same values as if you used the Fn::GetAtt intrinsic function.

更多详情请查看AWS - Fn::Sub

关于amazon-web-services - 使用 cloudformation (yaml) 在 Ubuntu 实例中启动 cfn-init,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49771677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com