Amazon web services 使用cloudformation调整ec2实例的根卷大小

Amazon web services 使用cloudformation调整ec2实例的根卷大小,amazon-web-services,amazon-ec2,amazon-cloudformation,Amazon Web Services,Amazon Ec2,Amazon Cloudformation,我有一个使用cloudformation创建的实例,如下所示: EC2Instance: Type: AWS::EC2::Instance Properties: ImageId: !Ref ServerAMI InstanceType: !Ref ServerInstanceType KeyName: !Ref KeyName BlockDeviceMappings: - DeviceName: /dev/xvda

我有一个使用cloudformation创建的实例,如下所示:

EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref ServerAMI
      InstanceType: !Ref ServerInstanceType
      KeyName: !Ref KeyName
      BlockDeviceMappings:
      - DeviceName: /dev/xvda
        Ebs:
          VolumeSize: 30
      NetworkInterfaces:
      - AssociatePublicIpAddress: 'false'
        DeleteOnTermination: 'true'
        DeviceIndex: '0'
        GroupSet:
        - Ref: ServerSecurityGroup
        SubnetId: !Ref SubnetID
      Tags:
      - { Key: Name, Value: !Ref AWS::StackName }
在本例中,我的根卷创建为30GB。如果我试图通过设置
VolumeSize
值来增加这个根卷大小,那么我的ec2实例将被终止并重新创建

然而,在控制台中,我可以增加根卷的大小,而无需重新创建实例

在尝试通过cloudformation增加根卷大小时,是否有任何解决方法可以防止ec2实例被终止

编辑: 这是一个小测试堆栈,我正在使用它再次进行测试。部署一次,然后更改VolumeSize并重新部署-它希望替换实例:

AWSTemplateFormatVersion: '2010-09-09'

Description: Test stack for a single ec2 instance

Parameters:

  ServerAMI:
    Type: String
    Default: ami-096f43ef67d75e998

  ServerInstanceType:
    Type: String
    Default: t2.small

  DefaultVPCID:
    Type: String

  SubnetID:
    Type: String

  KeyName:
    Type: AWS::EC2::KeyPair::KeyName

Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref ServerAMI
      InstanceType: !Ref ServerInstanceType
      KeyName: !Ref KeyName
      BlockDeviceMappings:
      - DeviceName: /dev/xvda #Linux
        Ebs:
          VolumeSize: 30
      NetworkInterfaces:
      - AssociatePublicIpAddress: 'false'
        DeleteOnTermination: 'true'
        DeviceIndex: '0'
        GroupSet:
        - Ref: ServerSecurityGroup
        SubnetId: !Ref SubnetID
      Tags:
      - { Key: Name, Value: !Ref AWS::StackName }

  ServerSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Webserver security group
      VpcId: !Ref DefaultVPCID
      SecurityGroupIngress:
      - { IpProtocol: tcp, FromPort: '22',   ToPort: '22',   CidrIp: '127.0.0.1/32',   Description: 'Test Instance'  }

VolumeSize
属性列为“更新要求:无中断”,因此我不确定您为什么会看到整个EC2实例被终止。这肯定是对模板的唯一更改吗?正确,我现在在一个小测试堆栈上做了一些测试。只更改体积大小。每次我得到替换(在Cloudformation中为True)。@KaiBurjack这对根卷有效吗?我还没有用根试过这个volume@WarrenG对不起,你说得对。它确实不适用于根卷。发现此问题,似乎是一个未解决的问题: