gpt4 book ai didi

amazon-web-services - 在 AWS Cloudformation 中使用最新的启动模板版本

转载 作者:行者123 更新时间:2023-12-03 07:13:45 25 4
gpt4 key购买 nike

我正在编写一个 cloudformation (cf) 模板来配置自动缩放组,我提前准备了启动模板并希望使用最新版本。

我获取 LaunchTemplateId 作为参数,但我不确定如何使用最新的午餐模板版本。

我的 cf 模板如下所示:

--- 
AWSTemplateFormatVersion: 2010-09-09
Description: Create Auto Scaling Group with 2 min, 2 desired, 4 max
Parameters:
...
TemplateID:
Description: Lunch Template for ASG EC2s
Type: String
Default: lt-xxxxxxxxxxxxxxxx
Resources:
ASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
...
LaunchTemplate:
LaunchTemplateId: !Ref TemplateID
Version: !GetAtt
- !Ref TemplateID
- LatestVersionNumber
...

但是当我运行 taskcat 进行测试时,我总是遇到这个 linting 错误:

[ERROR ] : Linting detected issues in: /Users/zaidafaneh/Desktop/RealBlocks/repos/cloudformation-temaplates/templates/saas/asg.yml

[ERROR ] : line 23 [1010] [GetAtt validation of parameters] Invalid GetAtt TemplateID.LatestVersionNumber for resource ASG

我正在考虑使用 Lambda 自定义资源作为解决方法,但我觉得这太多了。有没有办法通过cloudformation来做到这一点?

最佳答案

!GetAtt 仅适用于在模板中创建的资源,您不能使用它来获取参数的属性。

要实现所需的工作流程,您必须:

  1. 在同一模板中创建启动模板(然后您可以像现在一样使用 !GetAtt)
  2. 传入版本号作为附加参数。

如果启动模板是使用另一个 CloudFormation 模板创建的,则还有第三个选项:

  • 从其他模板导出启动模板资源并将其导入到您的模板中;然后你就可以使用 !GetAtt
  • 关于amazon-web-services - 在 AWS Cloudformation 中使用最新的启动模板版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73686608/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com