gpt4 book ai didi

amazon-ec2 - 为什么我的 Ubuntu EC2 实例的 DataUser 部分中的脚本没有运行?我正在使用云信息

转载 作者:行者123 更新时间:2023-12-03 07:17:05 28 4
gpt4 key购买 nike

我正在使用 CloudFormation 创建运行 Ubuntu 的 EC2 实例。我已将安装 pip 的命令和安装 cfn cloudformation 帮助程序脚本的命令插入到 EC2 实例的 UserData 属性中。也就是说,关键的cloudformation模板片段是:

"UserData" : {
"Fn::Base64" : {
"Fn::Join": ["", [
"#!/bin/bash -xe","\n",
"apt-get update","\n",
"apt-get install -y python-pip","\n",
"apt-get install -y python3","\n",
"apt-get install -y heat-cfntools","\n"
]
]
}
}

不,我没有元数据部分。问题:为什么脚本没有运行?以下是我在新创建的 EC2 实例上得到的输出:

ubuntu@ip-10-0-0-121 :~$ curl -s http://169.254.169.254/latest/user-data

#/bin/bash -xe
apt-get update
apt-get install -y python-pip
apt-get install -y heat-cfntools

该脚本从 Cloudformation 模板中列出的 EC2 资源的 DataUser 部分传输到实时 EC2 实例,但如下所示,该脚本未执行:

ubuntu@ip-10-0-0-121:~$ pip

The program 'pip' is currently not installed. You can install it by typing:
sudo apt install python-pip

ubuntu@ip-10-0-0-121:~$ vi /var/log/cloud-init.log

log show nothing that stands out.

ubuntu@ip-10-0-0-121:~$ cfn-init

The program 'cfn-init' is currently not installed. You can install it by typing:  
sudo apt install heat-cfntools

注意:当我不使用 Cloudformation 而是使用 EC2 控制台时,我在 EC2 的 UserData 部分运行相同的脚本,没有任何问题。

编辑:我经常使用aws cloudformation validate-template [NameOfTemplate]命令。但是,这个工具只能让我验证模板是否完全符合 JSON 语法。该工具不验证其他任何内容。如果模板被破坏,运行 Cloudformation 将导致回滚。 Cloudformation 一直运行直至报告完成。

最佳答案

有东西正在从 shebang (#!) 中删除您的 bang (!)。

在你的输出中,你有:

ubuntu@ip-10-0-0-121 :~$ curl -s http://169.254.169.254/latest/user-data
#/bin/bash -xe
apt-get update
apt-get install -y python-pip
apt-get install -y heat-cfntools

因此,cloudformation 正在读取“#/bin/bash”而不是“#!/bin/bash”,并且不知道如何执行它并且不执行任何操作。

我不知道为什么会发生这种情况以及如何修复它,但可能与您的上传过程相关的某些内容正在删除!

希望它对某人有所帮助,尽管这是一个老问题。

关于amazon-ec2 - 为什么我的 Ubuntu EC2 实例的 DataUser 部分中的脚本没有运行?我正在使用云信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43474843/

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