【问题标题】:Launch ec2 using cloudformation which should use launch template使用应该使用启动模板的 cloudformation 启动 ec2
【发布时间】:2020-04-19 19:13:45
【问题描述】:

我正在尝试使用启动模板创建一个 ec2 实例: 所以我创建了一个包含以下数据的启动模板。

LaunchTemplateVerybasic:

当我尝试运行如下所示的云形成模板时:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  TestTemplate:
    Type: 'AWS::EC2::Instance'
    Properties:
      LaunchTemplate:
        LaunchTemplateSpecification:
          LaunchTemplateId: lt-00d9f13eea240e524
          LaunchTemplateName: Testtemplate
          Version: '1'

我收到此错误:

遇到不受支持的属性 LaunchTemplateSpecification,而 在设计器中显示可以创建实例。

我错过了什么?我检查了文档,这是 AWS::EC2::instance 支持的属性..

如果我在理解和 yaml 中缺少什么,请告诉我

【问题讨论】:

    标签: amazon-web-services yaml amazon-cloudformation


    【解决方案1】:

    CloudFormation Linter 抓住这个:

    E3002 Invalid Property Resources/TestTemplate/Properties/LaunchTemplate/LaunchTemplateSpecification template.yaml:7:9

    尝试删除LaunchTemplateSpecification

    AWSTemplateFormatVersion: 2010-09-09
    Resources:
      TestTemplate:
        Type: 'AWS::EC2::Instance'
        Properties:
          LaunchTemplate:
            LaunchTemplateId: lt-00d9f13eea240e524
            LaunchTemplateName: Testtemplate
            Version: '1'
    

    AWS::EC2::Instance.LaunchTemplate documentation

    【讨论】:

    • 从您建议使用的模板中得到了一些错误- 1.我应该只使用一个(templateId 或 name),在修复它之后,我得到了以下错误。 2.“当前不支持请求的配置。请查看文档以获取支持的配置。(服务:AmazonEC2;状态代码:400;错误代码:不支持;请求 ID:11e03337-f295-4a75-b05c-5e1109b94686)”AWSTemplateFormatVersion: 2010-09-09 资源:TestTemplate:类型:'AWS::EC2::Instance' 属性:LaunchTemplate:LaunchTemplateId:lt-00d9f13eea240e524 版本:'1'
    • ID lt-00d9f13eea240e524 的 LaunchTemplate 是否与您的 CloudFormation 堆栈存在于同一账户和区域中?
    • 是同一地区
    • 您在哪个区域部署此模板? a1.medium 目前在 us-gov-east-1us-gov-west-1eu-north-1eu-west-3eu-west-2ap-northeast-3ap-northeast-2sa-east-1cn-north-1cn-north-1us-west-1us-west-1 @ 和 cn-northwest-1
    • us-east-1 ,具有 a1.medium
    【解决方案2】:

    由于 EC2 不是通过自动缩放组从启动模板启动的,而是通过资源定义启动的,因此您需要先删除并进行如下配置

      HostA:
        Type: AWS::EC2::Instance
        Properties:
          LaunchTemplate:
            LaunchTemplateId: !Ref HostALaunchTemplate
            Version: !GetAtt HostALaunchTemplate.LatestVersionNumber
    

    启动模板示例

    当通过自动伸缩组启动启动模板时,通常不需要在启动模板中指定网络接口,因为自动伸缩组会处理它。

    在您的启动模板中,删除 LaunchTemplateData 中的 SecurityGroupId

      HostALaunchTemplate:
        Type: AWS::EC2::LaunchTemplate
        Properties:
          LaunchTemplateName: HostALaunchTemplate
          LaunchTemplateData:
            SecurityGroupIds:
              - !ImportValue MyASG
    

    然后像这样通过网络接口添加安全组

      HostALaunchTemplate:
        Type: AWS::EC2::LaunchTemplate
        Properties:
          LaunchTemplateName: HostALaunchTemplate
            NetworkInterfaces:
              - DeviceIndex: 0
                Groups:
                  - !ImportValue MyASG
                SubnetId: !ImportValue MySubnet
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2018-10-06
      • 2020-04-23
      • 2023-03-31
      • 1970-01-01
      • 2021-04-18
      • 1970-01-01
      相关资源
      最近更新 更多