【问题标题】:How to create EC2 instance with EBS volume in CloudFormation?如何在 CloudFormation 中使用 EBS 卷创建 EC2 实例?
【发布时间】:2019-11-04 10:32:09
【问题描述】:

您好,我正在尝试使用 EBS 卷创建 Amazon EC2 实例。我创建了一个 CloudFormation 模板:

AWSTemplateFormatVersion: "2010-09-09"
Description: "First EC2 instance"
Resources:
 FirstLinuxEC2instance:
    Type: AWS::EC2::Instance
    Properties:
      AvailabilityZone: 'ap-southeast-2a'
      ImageId: 'ami-0c1d8842b9bfc767c'
      InstanceInitiatedShutdownBehavior: 'terminate'
      InstanceType: 't2.micro'
      SecurityGroupIds:
        - 'sg-79862305'
      Volumes:
        Device: "/dev/sdf"
        VolumeId: !Ref NewVolume
 NewVolume:
  Type: AWS::EC2::Volume
  Properties:
    Size: 1
    AvailabilityZone: 'ap-southeast-2a'
    Tags:
      - Key: MyTag
        Value: TagValue
  DeletionPolicy: Snapshot

当我上传此模板时,出现以下错误。

属性 Volumes 的值必须是 List 类型

谁能帮我解决这个问题?

【问题讨论】:

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


    【解决方案1】:

    试试这个!

    Volumes:
      -
       Device: "/dev/sdf"
       VolumeId: !Ref NewVolume
    

    【讨论】:

      【解决方案2】:

      是的,volumes 是数组类型。因此,即使是单个卷也需要放在一对方括号 (json) 中。你可以试试cloudkast,它是一个在线的cloudformation模板生成器。用内联描述明确哪个属性是什么类型是非常有用的。

      【讨论】:

        猜你喜欢
        • 2017-12-05
        • 2020-03-09
        • 2023-04-01
        • 2016-01-04
        • 1970-01-01
        • 1970-01-01
        • 2020-07-20
        • 1970-01-01
        • 2014-02-18
        相关资源
        最近更新 更多