Search code examples
jsonamazon-web-servicesamazon-ec2aws-cloudformation

AWS - connecting ec2 instance to gp3 instead of gp2 via CloudFormation template file


I am quite new to AWS and want to deploy an instance on gp3 EBS instead of gp2 (using AWS template),

when specifies my template file with EBS gp3,

it is deploying and attaching my instance both to gp2 and gp3.

How can I edit the file to it will attach it just to gp3?

here is part of my JSON template file:

"MyServer":{
   "Type":"AWS::EC2::Instance",
   "DependsOn":[
      "ExecuteCheckCompliance"
   ],
   "Properties":{
      "ImageId":{
         "Fn::FindInMap":[
            "Ami",
            {
               "Ref":"AWS::Region"
            },
            "ImageId"
         ]
      },
      "KeyName":{
         "Ref":"keyPairName"
      },
      "SecurityGroupIds":[
         {
            "Ref":"InstanceSecurityGroup"
         }
      ],
      "IamInstanceProfile":{
         "Ref":"RootInstanceProfile"
      },
      "InstanceType":{
         "Fn::FindInMap":[
            "Model2InstanceType",
            {
               "Ref":"Model"
            },
            "InstanceType"
         ]
      },
      "SubnetId":{
         "Ref":"Subnet"
      },
      "DisableApiTermination":"True",
      "BlockDeviceMappings":[
         {
            "DeviceName":"/dev/sdf",
            "Ebs":{
               "DeleteOnTermination":"True",
               "VolumeType":"gp3",
               "VolumeSize": 500
            }
         }
      ]
   }
}

Thank's a lot!


Solution

  • In your case, the volume you defined in your template is not actually the root volume of your instance, it is an additional volume that was created of type gp3; however the root volume was created with gp2 volume type.

    To check go to your EC2 AWS console --> storage tab, and check how many volumes do you have, you have to find 2.

    To fix, check what is the root device name of the ami you are using, by running and inspecting RootDeviceName field

    aws ec2 describe-images --region <<your_region>> --image-ids <<your_ami>>

    and then substitute /dev/sdf you have in your template with the value you got.