cfn-hup" on.demand"在Elastic Beanstalk中触发

时间:2014-10-02 14:38:19

标签: amazon-web-services elastic-beanstalk amazon-cloudformation

我已经将cfn-hup用于各种项目,并且已经跟随AWS documentation进行了cfn-hup。如该页面上所述,列出了以下触发器类型:

  • post.add
  • post.update
  • post.remove

我已经用它们取得了巨大的成功。最近,我正在审查用于学习目的的Elastic Beanstalk CloudFormation模板。 Elastic Beanstalk使用CloudFormation来配置和引导资源。他们使用cfn-hup,但在配置文件中有一个奇怪的触发器类型:

"\/etc\/cfn\/hooks.d\/aws-eb-command-handler.conf":{
  "content":{
    "Fn::Join":[
      "",
      [
        "[aws-eb-command-handler]",
        "\n",
        "triggers=on.command",
        "\n",
        "path=ElasticBeanstalkCommand-",
        "AWSEBAutoScalingGroup",
        "\n",
        "action=commandWrapper.py",
        "\n"
      ]
    ]
  }
},

如您所见,他们有一个“on.command”触发器类型。也许我是瞎子,但我无法在任何地方找到记录。这是一种特殊的内部触发类型,只允许使用Elastic Beanstalk吗?或者这只是另一个未记录的功能,如果是这样,它会做什么?

1 个答案:

答案 0 :(得分:2)

这种钩子类型确实是一个记录不足的类型。

on.command 是CloudFormation将cfn-hup命令绑定到SQS队列的方法。

要使用它,请在主要部分配置SQS队列:

[main]
sqs_url=https://sqs.eu-west-1.amazonaws.com/XXXXXXXX/cfn-hook-trigger

然后,在发送到该队列的消息后,您的命令将在该实例上执行。消息格式如下:

{
"InvocationId": "unique",
 "DispatcherId": "some value, participating in message and leader elections",
 "Expiration": "1433617216000", //timestamp
 "CommandName": "cfn-auto-reloader-hook", //or any other hook name
 "ResultQueue": "https://eu-west-1.queue.amazonaws.com/...", // mandatory if hook.send_result was
initialized
 "Data": null, //will populate ENV[CMD_DATA] env var; optional
 "EventHandle": null //will populate ENV[EVENT_HANDLE] env var; optional
}

如果所选挂钩的send_result = True,则使用指定的ResultQueue转储执行结果。消息格式如下:

{
"DispatcherId" : "copied from the inbound message",
 "InvocationId" : "copied from the inbound message",
 "CommandName" : "copied from the inbound message",
 "Status" : "FAILURE" | "SUCCESS",
 "ListenerId" : "FQDN or AWS instance id if applicable",
 "Data": "STDOUT", // data > 1Kb is treated as FAILURE
 "Message": "STDERR, if $? != 0" //or first 100 bytes of STDOUT if it was > 1Kb
}

此处的信息是从2015年6月python sources开始的。

实际上没有经过测试。

此外,AWS可能已经改变了行为,因为它甚至没有记录。