如何解决AWS CDK-Linux EC2实例Cloudformation初始化-/ opt / aws / bin / cfn-signal重新启动后无法正常运行
所以我试图通过cloudformation引导我的linux ec2实例。我想做的是:
- 更改主机名
- 重启
- 发送完整信号
所以我这里有aws cdk python代码:
testInit = ec2.CloudFormationInit.from_config_sets(
config_sets={
"test_configsets" : ["change_hostname","reboot","cfn-signal"]
},configs={
"change_hostname" : ec2.InitConfig([
ec2.InitCommand.shell_command("> /etc/hostname ; echo testInstance > /etc/hostname",key = "change_hostname")
]),"reboot" : ec2.InitConfig([
ec2.InitCommand.shell_command("reboot",key = "reboot")
]),"cfn-signal" : ec2.InitConfig([
ec2.InitCommand.shell_command(core.Fn.sub("/opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackId} --resource TestInstance --region ${AWS::Region}"),key = "signal_complete")
])
}
)
由于重新启动将导致用户数据部分上的cfn信号无法运行,因此我将cfn信号放置在AWS :: CloudFormation :: Init元数据部分上,而不是在重新启动命令之后希望它将发送重启后成功信号。我在Windows实例上尝试了这种方法,并且效果很好(https://aws.amazon.com/premiumsupport/knowledge-center/create-complete-bootstrapping/)
change_hostname and reboot命令成功运行,但随后无限期地卡在cfn-signal命令中,最终由于超时而无法创建堆栈。我试图通过ssh对实例运行cfn信号,并且效果很好。
当我回显cfn_signal的命令块时,Cloudformation伪参数参考也可以很好地解析。
这是相关代码块的cdk合成器输出
Metadata:
aws:cdk:path: cdk-ec2/TestInstance/Resource
AWS::CloudFormation::Init:
configSets:
test_configsets:
- change_hostname
- reboot
- cfn-signal
change_hostname:
commands:
change_hostname:
command: "> /etc/hostname ; echo testInstance > /etc/hostname"
reboot:
commands:
reboot:
command: reboot
cfn-signal:
commands:
signal_complete:
command:
Fn::Sub: /opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackId} --resource TestInstance --region ${AWS::Region}
这是/var/log/cfn-init.log的输出
[INFO] Running config cfn-signal
[DEBUG] No packages specified
[DEBUG] No groups specified
[DEBUG] No users specified
[DEBUG] No sources specified
[DEBUG] No files specified
[DEBUG] Running command signal_complete
[DEBUG] No test for command signal_complete
感谢任何帮助!
谢谢, 谢尔顿
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。