amazon-ec2 - 云形成等待条件超时,但脚本执行成功 + 发送 CFN 信号

标签 amazon-ec2 aws-cloudformation

我想在 ubuntu 上设置 EC2。 EC2 设置完毕后,将运行一个脚本来安装多个软件包。日志 (/var/log/cloud-init-output.log) 显示脚本没有错误并发送成功完成信号。

日志

+ /usr/local/bin/cfn-signal -e 0 -r 'AWS CodeDeploy Agent setup complete.' 'https://cloudformation-waitcondition-eu-central-1.s3.eu-central-1.amazonaws.com/arn%3Aaws%3Acloudformation%3Aeu-central-1%XXXXXXXXX%3Astack/XXXXXXXXXX/XXXXXXXX-XXXX-11e6-9ec8-50a68ad4f262/WaitHandle?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20160608T172814Z&X-Amz-SignedHeaders=host&X-Amz-Expires=86399&X-Amz-Credential=XXXXXXXXXXXXXX%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Signature=XXXXXXXXXXXXXXX'
/usr/local/lib/python2.7/dist-packages/cfnbootstrap/packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
CloudFormation signaled successfully with SUCCESS.
Cloud-init v. 0.7.5 finished at Wed, 08 Jun 2016 17:34:00 +0000. Datasource DataSourceEc2.  Up 99.87 seconds

PS:我添加了一些`X,链接中有真正的字母数字字符。

代码脚本

"UserData": {
  "Fn::Base64": {
    "Fn::Join": [
      "",
      [
        "#!/bin/bash -ex\n",
        "apt-get update\n",
        "apt-get -y install python-pip\n",
        "apt-get -y install python-setuptools\n",
        "apt-get -y install ruby2.0\n",
        "apt-get install -y awscli\n",
        "pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
        "# Helper function.\n",
        "function error_exit\n",
        "{\n",
          "/usr/local/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref": "WaitHandle" }, "'\n",
          "exit 1\n",
        "}\n",
        "#Install nodejs, npm\n",
        "curl -sL https://deb.nodesource.com/setup_6.x\n",
        "apt-get install -y nodejs npm || error_exit 'Failed to install nodejs.'\n",
        "npm install pm2 -g || error_exit 'Failed to install pm2.'\n",
        "# Install the AWS CodeDeploy Agent.\n",
        "cd /home/ubuntu/\n",
        "aws s3 --region eu-west-1 cp 's3://aws-codedeploy-eu-west-1/latest/install' . || error_exit 'Failed to download AWS CodeDeploy Agent.'\n",
        "chmod +x ./install\n",
        "./install auto\n",
        "/usr/local/bin/cfn-init --stack ", { "Ref":"AWS::StackId" }, " --resource LinuxEC2Instance", " --region ", { "Ref": "AWS::Region" }, "\n",
        "# All is well, so signal success.\n",
        "/usr/local/bin/cfn-signal -e 0 -r \"AWS CodeDeploy Agent setup complete.\" '", { "Ref": "WaitHandle" }, "'\n"
      ]
    ]
  }
},

代码等待条件

"WaitHandle": {
  "Type": "AWS::CloudFormation::WaitConditionHandle",
  "Metadata": {
    "AWS::CloudFormation::Designer": {
      "id": "761ddc9a-7c3b-41ca-9fa1-21429046b271"
    }
  }
},
"WaitCondition": {
  "Type": "AWS::CloudFormation::WaitCondition",
  "Properties": {
    "Count": {
      "Ref": "InstanceCount"
    },
    "Handle": {
      "Ref": "WaitHandle"
    },
    "Timeout": "300"
  },
  "Metadata": {
    "AWS::CloudFormation::Designer": {
      "id": "a2c91b03-2c8c-4bd5-9c44-efdb89cf5375"
    }
  }
},

问题

为了让脚本通过,我需要更改什么。

最佳答案

如果未使用 "pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn- 安装 aws-cfn-bootstrap,则问题似乎不会出现bootstrap-latest.tar.gz\n", 现在我使用 easy install 并直接调用可执行文件,例如cfn-signal -e 0 -r\"AWS CodeDeploy 代理设置完成。\"'", { "Ref": "WaitHandle"}, "'\n"

关于amazon-ec2 - 云形成等待条件超时,但脚本执行成功 + 发送 CFN 信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37709437/

相关文章:

linux - 如何将文件从 Linux 实例正确复制到 aws ec2 实例?

aws-cloudformation - 使用Cloudformation在新帐户上构建环境

amazon-web-services - 如何通过 CloudFormation 为 lambda 函数配置 Alexa Skills Kit 触发器?

amazon-web-services - 云形成无法创建带有 VPCIdNotSpecified 的安全组

linux - AWS Linux : illegal intrusion attempts against remote hosts on the Internet. 预防方法?

mongodb - mongoRestore 问题 [listCollections 需要身份验证]

amazon-web-services - 如何创建 lambda boto3 函数以在另一个 AWS 账户中创建 cloudformation 堆栈

amazon-web-services - Elastic beanstalk动态创建和删除单个实例的警报

amazon-ec2 - 如何使用AWS cloudformation启动EC2实例

amazon-web-services - CloudWatch 上的 EC2 Docker 容器日志