【问题标题】:Creating a cloudFormation waitCondition with constant timeout创建具有恒定超时的 cloudFormation waitCondition
【发布时间】:2017-04-22 00:05:06
【问题描述】:

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

我想使用带有 timeout 属性 的 cloudFormation 的 WaitCondition 来解决这个问题。但它需要一个 WaitHandle,它必须在超时之前接收成功信号。收到信号后,WaitCondition 将变为 Create-Complete。 但在我的情况下,我无法使用自定义函数将信号发送到等待句柄。 第一个自定义资源完成后,我需要有一个恒定的 3 分钟等待时间。 然后,在 创建完成 之后开始创建 第二个自定义资源 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 保持不变?

【问题讨论】:

  • 堆栈中是否有一个实例可以提供“睡眠”然后向句柄发出信号?
  • 没有。我正在自定义函数中部署一个 kubernetes 集群。从 Google 云发送成功信号会很困难。

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

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

大概吧。我想你想通过做这两件事来尝试一下。 1. 在 FirstCustomResourceFunction 中加入一个“sleep”函数,该函数在发出成功信号之前会休眠 3 分钟。看到这个,超级重要,找“SUCCESS”http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html

  1. 让 SecondCustomResourceFunction 依赖于 FirstCustomResource。这样,在 FirstCustomResource 完成之前它不会启动(也就是 sleep 然后成功)。

我认为你可以摆脱 WaitConditions。

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

【讨论】:

  • 有趣!!我是这么想的,但是当我在 Lambda 内部等待集群将状态更改为 Running 时,它会很昂贵。我理解你对持续 3 分钟的担忧,我想我必须想出一些其他的解决方案。
  • Lambda 限制现在为 900 秒(15 分钟)docs.aws.amazon.com/lambda/latest/dg/limits.html
猜你喜欢
  • 1970-01-01
  • 2018-03-11
  • 2019-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-25
  • 2014-01-10
  • 2021-03-14
相关资源
最近更新 更多