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

标签 amazon-web-services amazon-ec2 aws-cloudformation infrastructure-as-code aws-auto-scaling

我正在编写一个 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/

    相关文章:

    amazon-web-services - ECS服务不稳定

    amazon-web-services - 为什么函数 Fn::GetAtt 函数给我错误?

    amazon-web-services - Cloudwatch仪表板主体的Cloudformation子功能

    mysql - Amazon ec2 linux 实例 mysql 未连接

    postgresql - AWS docker multicontainer应用程序上的哪个postgres连接字符串?

    amazon-web-services - Athena 中 YYYY-MM-DD 日期格式的字符串

    amazon-ec2 - EC2 上的应用程序如何自动发现 ElastiCache 实例?

    hadoop - 不能 ssh 权限被拒绝。 HBase Hadoop

    java - 通过 http 集成两个 Java webapps 的 IO 错误

    amazon-web-services - 在 AWS 上的视频点播解决方案上实现 DRM