2016-02-01 54 views
0

我試圖從AWS Cloudformation模板中的啓動配置的用戶數據運行shell腳本。我用一些腳本創建了AMI。啓動配置用戶數據shell腳本不從CloudForms運行

這裏是例如,從LaunchConfiguration的Cloudformation模板:

"ProcessLC": { 
     "Type" : "AWS::AutoScaling::LaunchConfiguration", 
     "Properties" : { 
      "ImageId": {"Ref" : "GeneralAMI"}, 
      "InstanceType" : "t2.medium", 
      "SecurityGroups" : [{"Ref": "SecurityGroup"}], 
      "KeyName" : {"Ref": "KeyPair"}, 
      "UserData": {"Fn::Base64": {"Fn::Join": ["", [ 
       {"Fn::Join": ["", ["Env=",{"Ref": "Env"}," \n"]]}, 
       {"Fn::Join": ["", ["DBConn=", {"Ref": "Database"}," \n"]]}, 
       {"Fn::Join": ["", ["DBEngine=", {"Ref": "Metabase"}," \n"]]}, 
       "#!/bin/bash\n", 
       "cd /project/\n", 
       "./stop.sh\n", 
       "./vpcAssignIP.sh\n" 
       ] 
      ] 
      } 
     } 
     } 
    } 

它不運行(正如我在日誌「/var/log/cloud-init.log」見),當我創建堆棧。 我做錯了什麼?

謝謝!

回答

2

把這條線放在最上面,而不是更下來: 「#!/ bin/bash \ n」。該行告訴它將整個腳本處理爲bash命令。它必須是第一行。 (所以,在你的加入,如果你把它放在「」,而不是加入後,你應該是不錯的。)

編輯: 有了您的加入,這應該工作:

"UserData": {"Fn::Base64": {"Fn::Join": ["", [ 
       "#!/bin/bash\n", 
       {"Fn::Join": ["", ["Env=",{"Ref": "Env"}," \n"]]}, 
       {"Fn::Join": ["", ["DBConn=", {"Ref": "Database"}," \n"]]}, 
       {"Fn::Join": ["", ["DBEngine=", {"Ref": "Metabase"}," \n"]]}, 
       "cd /project/\n", 
       "./stop.sh\n", 
       "./vpcAssignIP.sh\n" 
       ] 
+0

所以如果「fn :: join」將在bash腳本之後,它們將不起作用,不是嗎? – muzafarow

+0

您必須將您的連接輸出「#!/ bin/bash \ n」作爲第一行。目前,您的連接輸出該行作爲第四行。查看我編輯的代碼片段。 –