使用常量超时

时间:2017-04-21 10:12:02

标签: amazon-web-services amazon-cloudformation

我在 cloudFormation模板中使用两个自定义资源基本上这些自定义资源是具有自定义代码的lambda函数。我希望在常量3分钟之后开始 第二个lambda 创建

我认为使用cloudFormation的 WaitCondition 超时属性来解决此问题。但是它需要一个 WaitHandle ,它必须在超时之前接收成功信号。收到信号后,WaitCondition将转为 Create-Complete。但在我的情况下,我无法使自定义函数向wait句柄发送信号。完成第一个自定义资源后,我需要有一个恒定的3分钟等待时间。然后,在创建完成后>开始创建第二个自定义资源 strong> WaitCondition。这是我的代码:

"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"
  }
}

这似乎不起作用。任何hack或解决方案都有一个恒定的WaitCondition?

1 个答案:

答案 0 :(得分:0)

  
    

我只想在我的第一个和第二个自定义资源之间等待3分钟。这可能吗 ? <<

  

可能。我认为你想通过做这两件事来尝试它。 1.将“睡眠”功能放入FirstCustomResourceFunction,该功能在信号成功之前休眠3分钟。看到这个,非常重要,寻找“成功”http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html

  1. 让SecondCustomResourceFunction依赖于FirstCustomResource。这样,直到FirstCustomResource完成(即睡眠然后成功),它才会启动。
  2. 我认为你可以摆脱WaitConditions。

    请注意“所有对AWS Lambda的调用必须在300秒内完成执行。” (https://aws.amazon.com/lambda/faqs/)因此,如果您的部署增长了60%,那么您可能已经熟了。 (这是我试图引导你远离使用Lambda作为等待状态的原因之一)。我真的会尝试找到更好的方法。作为DevOps的15年,我从来没有达到“恒定价值等待状态”是一个成功的长期解决方案。