amazon-web-services - 创建具有恒定超时的 cloudFormation waitCondition

标签 amazon-web-services aws-cloudformation

我在我的 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 吗?

最佳答案

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/

    相关文章:

    amazon-web-services - 设置 GatewayResponse 时指定的映射表达式无效

    integration-testing - 如果 CodeBuild 失败,则删除 CloudFormation 堆栈

    amazon-web-services - 如何在另一个 AWS 账户中使用 'hosted zone' 创建 'reusable delegation set'?

    amazon-web-services - 无法获取 LetsEncrypt SSL 证书以与 AWS Lightsail 配合使用

    amazon-web-services - AWS API网关Cognito - 如何从 react 应用程序获取

    amazon-web-services - 如何在cfn模板的bucketpolicy中指定多个bucket?

    ruby - 使用适用于 Ruby 的 AWS 开发工具包发布到 SNS 主题时指定区域

    java - Java中弹性计算节点的架构选项

    amazon-web-services - 如何在 Cloudformation 模板内为 AWS Lambda 定义 MetricFilter?

    amazon-web-services - AWS 云形成 : Route table not populating