2015-03-19 57 views
0

我有以下CloudFormation脚本,它可以正确设置所有基础结构。当我从CloudFormation收到CREATE_COMPLETE消息时,可以通过SSH访问EC2,但应用程序尚未安装。如果我等3分钟,他们就会出现。CloudFormation模板安装但没有指示脚本何时结束

有什么办法可以让CloudFormation等到所有元数据安装好(git和htop)?

以下脚本:

{ 
"AWSTemplateFormatVersion": "2010-09-09", 
"Description": "My first CloudFormation template", 

"Resources": { 
    "WebServerInstance": { 
     "Type": "AWS::EC2::Instance", 
     "Properties": { 
      "ImageId": "ami-abeb9e91", 
      "InstanceType": "t2.micro", 
      "KeyName": "test-key-pair", 
      "SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ], 
      "UserData": { 
       "Fn::Base64": { "Fn::Join":["", [ 
        "#!/bin/bash -ex\n", 
        "apt-get update\n", 
        "apt-get -y install python-setuptools\n", 
        "mkdir aws-cfn-bootstrap-latest\n", 
        "curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1\n", 
        "easy_install aws-cfn-bootstrap-latest\n", 
        "sudo /usr/local/bin/cfn-init --stack ", { "Ref":"AWS::StackName" }, " --resource WebServerInstance", " --region ", { "Ref": "AWS::Region" }, "\n", 
        "\n", 
        "/usr/local/bin/cfn-signal --exit-code $?" 
       ]]} 
      } 
     }, 
     "Metadata": { 
      "AWS::CloudFormation::Init": { 
       "config": { 
        "packages": { 
         "apt": { 
          "htop": [], 
          "git": [] 
         } 
        } 
       } 
      } 
     } 
    } 
} 

}

回答