2017-04-18 29 views
1

我正在使用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一直運行到報告完成。

+0

嘗試使用'aws cloudformation validate-template'驗證您的模板,如下所示。 http:// stackoverflow。com/questions/11854772/how-can-i-quick-and-effective-debug-cloudformation-templates – mootmoot

+0

檢查實例的系統日誌,可以從aws控制檯本身檢查並查看是否有任何內容被記錄,而用戶數據部分正在執行。 – omuthu

+0

共享'/ var/log/cloud-init-output.log'的完整輸出。 – wjordan

回答

0

有些東西正在將你的爆炸(!)從shebang(#!)中刪除。

輸出上有你有:

[email protected] :~$ 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是閱讀,而不是「#/斌/慶典」,「#! /斌/慶典」,不知道如何執行它和沒有做任何事情。

我不知道爲什麼會發生這種情況,以及如何解決這個問題,但可能與您的上傳過程有關的是刪除

希望它可以幫助某人,雖然這是一個老問題。

+0

「的UserData」:{ 的 「Fn :: Base64編碼」:{ 的 「Fn ::加入」: 「」, [ 「#/斌/慶典-xe」, 「/ N」, { 「參考」: 「的UserData」 } ] ] }} 我 在參數userdata給出了以下的shell命令 \t 「apt-get的更新」, 「\ n」,「易於得到安裝的Apache2 -y 「,」\ n「,」apt-get install -y php「,」\ n「 它也不起作用@GMartinez –

+0

如何實現通過userdata參數也一樣 –

相關問題