我正在使用CloudFormation創建運行Ubuntu的EC2實例。我已經在EC2實例的UserData屬性中插入了安裝pip的命令和用於安裝cfn cloudformation helper腳本的命令。即,關鍵的雲形成模板片段是:爲什麼我的Ubuntu EC2實例的DataUser部分中的腳本沒有運行?我正在使用CloudForms
"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:〜$捲曲-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 isntance的EC2資源上市的DataUser部分轉移,但你可以看到下面的腳本不執行:
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:〜$六/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一直運行到報告完成。
嘗試使用'aws cloudformation validate-template'驗證您的模板,如下所示。 http:// stackoverflow。com/questions/11854772/how-can-i-quick-and-effective-debug-cloudformation-templates – mootmoot
檢查實例的系統日誌,可以從aws控制檯本身檢查並查看是否有任何內容被記錄,而用戶數據部分正在執行。 – omuthu
共享'/ var/log/cloud-init-output.log'的完整輸出。 – wjordan