0

我正在尝试创建一个 Amazon EC2 实例,然后创建一个 Amazon EBS 卷并将其附加到该实例。我为此使用了 CloudFormation 模板。不幸的是,将新创建的卷附加到实例时堆栈创建失败,并出现以下错误:

实例“i-01eebc8c9c492c035”未“运行”。(服务:AmazonEC2;状态代码:400;错误代码:IncorrectState;请求 ID:635572fd-dd25-4a02-9306-6e22f88e13dc)

我不明白的是,当实例创建完成时,这意味着实例已启动并正在运行。这个错误怎么可能发生?

我正在使用以下 CloudFormation 模板:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "single instance template",
  "Parameters": {
    "InstanceType": {
      "Type": "String",
      "Default": "t2.micro"
    },
    "InstanceName": {
      "Type": "String",
      "Default": "test_CFT"
    },
    "RootVolumeSize": {
      "Type": "String",
      "Default": "50"
    },
    "Volume1Size": {
      "Type": "String",
      "Default": "8"
    },
    "Region": {
      "Type": "String",
      "Default": "us-east-2"
    },
    "AMIID": {
      "Type": "String",
      "Default": "ami-8c122be9"
    },
    "SubnetIds": {
      "Type": "CommaDelimitedList",
      "Default": "subnet-595e7422"
    },
    "SecurityGroupIDs": {
      "Type": "CommaDelimitedList",
      "Default": "sg-082faee8335351537"
    }
  },
  "Resources": {
    "Instance": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "ImageId": {
          "Ref": "AMIID"
        },
        "InstanceType": {
          "Ref": "InstanceType"
        },
        "KeyName": "thehope",
        "NetworkInterfaces": [
          {
            "AssociatePublicIpAddress": "false",
            "DeviceIndex": "0",
            "SubnetId": {
              "Fn::Select": [
                0,
                {
                  "Ref": "SubnetIds"
                }
              ]
            },
            "GroupSet": {
              "Ref": "SecurityGroupIDs"
            }
          }
        ],
        "BlockDeviceMappings": [
          {
            "DeviceName": "/dev/sda1",
            "Ebs": {
              "VolumeSize": {
                "Ref": "RootVolumeSize"
              },
              "DeleteOnTermination": "true",
              "VolumeType": "gp2"
            }
          }
        ],
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Ref": "InstanceName"
            }
          }
        ]
      }
    },
    "Volume1": {
      "DeletionPolicy": "Delete",
      "Properties": {
        "AvailabilityZone": {
          "Fn::GetAtt": [
            "Instance",
            "AvailabilityZone"
          ]
        },
        "Encrypted": "False",
        "Size": {
          "Ref": "Volume1Size"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "New_volume"
          }
        ],
        "VolumeType": "gp2"
      },
      "Type": "AWS::EC2::Volume"
    },
    "VolumeAttachment1": {
      "Properties": {
        "Device": "/dev/xvdb",
        "InstanceId": {
          "Ref": "Instance"
        },
        "VolumeId": {
          "Ref": "Volume1"
        }
      },
      "Type": "AWS::EC2::VolumeAttachment"
    }
  },
  "Outputs": {
    "InstanceId": {
      "Description": "InstanceId of the instance",
      "Value": {
        "Ref": "Instance"
      }
    },
    "AZ": {
      "Description": "Availability Zone of the instance",
      "Value": {
        "Fn::GetAtt": [
          "Instance",
          "AvailabilityZone"
        ]
      }
    },
    "PrivateIP": {
      "Description": "PrivateIP of the instance",
      "Value": {
        "Fn::GetAtt": [
          "Instance",
          "PrivateIp"
        ]
      }
    }
  }
}

我究竟做错了什么?

4

3 回答 3

0

看看实例是如何停止的,这非常令人着迷!

使用Amazon Linux 2时,可以通过更改来修复:

"DeviceName": "/dev/sda1",

进入:

"DeviceName": "/dev/xvda",

或者,可以使用Amazon Linux(版本 1)和/dev/sda1.

但是,这并不能解决您的VolumeAttachment问题。

于 2018-08-26T23:51:00.760 回答
0

由于您正在创建新卷,因此只需将卷指定为实例的一部分而不是指定 Amazon EBS 卷然后将其附加到实例会更容易。

Amazon EC2 块设备映射属性 - AWS CloudFormation

此示例将 EBS 支持的根设备 (/dev/sda1) 大小设置为 50 GiB,另一个 EBS 支持的设备映射到 /dev/sdm,大小为 100 GiB。

"BlockDeviceMappings" : [
   {
      "DeviceName" : "/dev/sda1",
      "Ebs" : { "VolumeSize" : "50" }
   },
   {
      "DeviceName" : "/dev/sdm",
      "Ebs" : { "VolumeSize" : "100" }
   }
] 
于 2018-08-25T22:37:22.303 回答
0

在我更改模板中的 AMI 之前,我遇到了同样的问题。最初,我在 N.Virginia 地区使用 Linux AMI 进行测试,但它失败了,但是当我使用我订阅的 CENTOS AMI 时,它可以工作。

于 2020-01-19T22:00:12.607 回答