amazon-web-services - 如何将 CloudFormation WaitHandle 传递到不同的 Cloudformation 堆栈?

标签 amazon-web-services aws-cloudformation

由于云形成堆栈中资源数量的限制,我们需要有多个堆栈,其中我们的主堆栈启动几个其他较小的子堆栈。我们在主堆栈中创建了等待条件,需要将其传递给某些子堆栈中的资源。目前,我们在 WaitHandle 上等待整个子堆栈,而不是子堆栈中的各个资源。然而,这不必要地显着增加了我们的启动时间。 为了解决这个问题,我尝试将 WaitHandle 作为参数传递给子堆栈,但我不确定参数的类型是什么。 我还听到我的同事说您可以尝试将 WaitHandle 的 URL 作为字符串传递,然后尝试在子堆栈中使用该 url 创建一个新的 WaitHandle,但我没有看到任何相关文档。 我想要做的事情在 CloudFormation 中是否可行?

最佳答案

是的,这是可能的。用于将 WaitHandle URL 作为字符串传递到子堆栈,根据 AWS::CloudFormation::WaitConditionHandle文档,

When you reference the WaitConditionHandle resource by using the Ref function, AWS CloudFormation returns a presigned URL. You pass this URL to applications or scripts that are running on your Amazon EC2 instances to send signals to that URL.

实际上有两种不同的方法可以实现您的目标:

  1. {"Ref": "MyWaitHandle"} 作为参数传递给您的子堆栈,然后让子堆栈中的资源包含此参数(例如,使用 ${ParentWaitHandle} Fn::Sub 字符串中的 )作为预签名 URL,使用 HTTP PUT 请求(例如使用 cURL,如 Creating Wait Conditions in a Template 演练中使用的)发送“等待条件信号” ):

curl -X PUT -H 'Content-Type:' --data-binary '{"Status": "SUCCESS", "Reason": "配置完成","UniqueId": "$UNIQUE_ID", "Data": "应用程序已完成配置。"}' "${ParentWaitHandle}"

  • 仅将 WaitCondition 资源名称传递给子堆栈(通过 Ref),并使用 SignalResource CloudFormation 服务 API 调用直接向 WaitCondition 资源发出信号。这使您可以跳过处理单独的 WaitConditionHandle 资源,但需要向信令资源授予 cloudformation:SignalResource IAM 权限才能进行 API 调用。例如,使用 AWS CLI:
  • aws cloudformation 信号资源\ --状态成功\ --unique-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id)\ --逻辑资源 ID ${ParentWaitCondition}\ --堆栈名称 $PARENT_STACK\ --region ${AWS::Region}\ ||真的

    关于amazon-web-services - 如何将 CloudFormation WaitHandle 传递到不同的 Cloudformation 堆栈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40580266/

    相关文章:

    amazon-web-services - 如何使用无服务器部署没有身份源的 API 网关自定义授权方?

    amazon-web-services - EC2实例与ELB不在同一VPC中。无效实例

    amazon-web-services - AWS CloudFormation导出yaml文件

    amazon-web-services - 收集 AWS Lambda 执行数据

    java - 嵌入式 Tomcat 不会在 AWS Elastic Beanstalk 中监听端口 80

    amazon-web-services - 使用 vendia serverless-express 的 lambda 可以成为状态机中的一个步骤吗?

    amazon-web-services - AWS KMS cloudformation 模板标签

    amazon-web-services - AWS EC2 - 多个(公共(public)/私有(private))网络接口(interface)

    aws-cloudformation - 如何将 Route53 A 记录定位到 ApiGateway v2

    amazon-web-services - 保存时挂起的 Spark Dataframe