Hello, this is aayush from classmethod, in this blog I summarize the steps to change the size of the root volume, enable encryption of the root volume and volume type of the root volume using cloudformation
Identify the device name of the root volume of your AMI
In Management Console:
1. Go to Amazon EC2 console.
2. From the navigation bar, select the AWS Region where you want to launch your instances.
3. In the navigation pane, choose AMIs Marked as 1 in the figure
3. In the filter you can select public images and write your AMI
4. On the Details tab, find the Root Device Name. This is where your root device name is listed.
Set the properties of the root volume for your EC2 instance
in Cloudformation use BlockDeviceMapping property of an AWS::EC2::Instance resource to set the properties(volumeType,volumeSize,DeleteonTermination) of the root volume for your EC2 instance.
In the following YAML Template, AWS CloudFormation creates an EC2 instance with the size of the root volume set to 30 GB, volumeType: gp3. DeleteOnTermination true DeviceName /dev/sda1 "because the AMI specified is an Amazon windows 2022 AMI" Encrypted: true "which enables default encryption on the root volume"
AWSTemplateFormatVersion: 2010-09-09
Parameters:
KeyName:
Type: 'AWS::EC2::KeyPair::KeyName'
Description: Name of an existing EC2 KeyPair to enable RDP access to the EC2 instance.
InstanceType:
Description: EC2 instance type
Type: String
Default: t2.micro
ConstraintDescription: Please choose a valid instance type.
Resources:
WindowsInstance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-01369a507eba1f7df
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeType: gp3
VolumeSize: '30'
DeleteOnTermination: 'false'
Encrypted: 'true'
Reference:
https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-root-volume-property/