2

我已经为各种项目使用了cfn-hup,并且针对cfn-hup遵循了AWS documentation。该网页上记载,有下面列出的触发类型:cfn-hup“on.demand”Elastic Beanstalk中的触发器

  • 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

这个钩子类型的确是一个没有记录的类型。

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 =真对于所选择的钩,然后指定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可能已经改变了行为,因为它甚至没有记录。