我在我的 cloudFormation 模板中使用两个自定义资源。基本上,这些自定义资源是具有自定义代码的 lambda 函数。我想在持续 3 分钟后开始创建第二个 lambda。
我想使用cloudFormation的WaitCondition和超时属性来解决这个问题。但它需要一个 WaitHandle ,它必须在超时之前接收到成功信号。一旦收到信号,WaitCondition 就会变为 Create-Complete。。但就我而言,我无法创建自定义函数来将信号发送到等待句柄。在完成第一个自定义资源后,我需要有恒定的 3 分钟等待时间。然后,在创建完成之后开始创建第二个自定义资源 WaitCondition的strong>。这是我的代码:
"SecondCustomResource": {
"Type": "Custom::SecondCustomResource",
"DependsOn" : "WaitCondition",
"Properties": {
"ServiceToken": { "Fn::GetAtt" : ["SecondCustomResourceFunction", "Arn"] }
}
},
"SecondCustomResourceFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": { "Ref": "S3Bucket" },
"S3Key": { "Ref": "S3Key" }
},
"Handler": { "Fn::Join" : [ "", [{ "Ref": "ModuleName" },".handler"] ] },
"Runtime": "nodejs4.3",
"Timeout": "30"
}
},
"WaitCondition": {
"Type" : "AWS::CloudFormation::WaitCondition",
"DependsOn" : "FirstCustomResource",
"Properties": {
"Timeout": "180"
}
},
"FirstCustomResource": {
"Type": "Custom::FirstCustomResource",
"Properties": {
"ServiceToken": { "Fn::GetAtt" : ["FirstCustomResourceFunction", "Arn"] }
}
},
"FirstCustomResourceFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": { "Ref": "S3Bucket" },
"S3Key": { "Ref": "S3Key" }
},
"Handler": { "Fn::Join" : [ "", [{ "Ref": "ModuleName" },".handler"] ] },
"Runtime": "nodejs4.3",
"Timeout": "30"
}
}
这似乎不起作用。有什么技巧或解决方法可以保持恒定的 WaitCondition 吗?
最佳答案
block 引用>I just want a constant 3 minute wait time between my first and second custom resource. Is this possible ? <<
也许吧。我想你想通过做这两件事来尝试一下。 1. 将“ sleep ”函数放入 FirstCustomResourceFunction 中,该函数在发出成功信号之前 sleep 3 分钟。看到这个, super 重要,找“SUCCESS”http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html
- 让 SecondCustomResourceFunction 依赖于 FirstCustomResource。这样,在 FirstCustomResource 完成之前它不会启动(也称为 sleep ,然后成功)。
我认为你可以摆脱 WaitConditions。
请注意,“对 AWS Lambda 的所有调用必须在 300 秒内完成执行。”。 ( https://aws.amazon.com/lambda/faqs/ ) 因此,如果您的部署增长了 60%,那么您可能已经成熟了。 (这就是我试图引导您不要使用 Lambda 作为等待状态的原因之一)。我真的会尝试找到更好的方法。在担任 DevOps 的 15 年里,我从未将“恒定值等待状态”视为成功的长期解决方案。
关于amazon-web-services - 创建具有恒定超时的 cloudFormation waitCondition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43539945/