AWS EBS volume bulk modification from GP2 to GP3 using lambda
Amazon Web Services (AWS) offers a range of storage options to cater to different performance and cost requirements. Among these, Amazon…
AWS EBS volume bulk modification from GP2 to GP3 using lambda
Amazon Web Services (AWS) offers a range of storage options to cater to different performance and cost requirements. Among these, Amazon Elastic Block Store (EBS) provides scalable and high-performance block storage that can be attached to Amazon Elastic Compute Cloud (EC2) instances. Two commonly used EBS volume types are GP2 (General Purpose SSD) and GP3 (General Purpose SSD, Next-Generation).
GP2 volumes have been a reliable choice for a wide variety of workloads, but with the introduction of GP3 volumes, AWS has provided an even more flexible and cost-effective option for users. GP3 volumes offer the same baseline performance as GP2 but introduce the ability to independently adjust both provisioned IOPS (Input/Output Operations Per Second) and volume size, allowing you to tailor your storage to your specific needs more precisely.
Migrating from GP2 to GP3 is a straightforward process and can be done without significant downtime for your applications. This migration not only enables you to potentially reduce your storage costs but also gain more control over your volume’s performance characteristics.
In this guide, we will explore the steps and best practices for migrating your AWS EBS volume type from GP2 to GP3. We’ll cover the prerequisites, the migration process itself, and important considerations to ensure a smooth transition while minimizing any disruption to your workloads.
By the end of this guide, you will have a clear understanding of how to leverage the advantages of GP3 volumes, optimize your storage costs, and fine-tune your EBS volumes for better performance, all while maintaining the reliability and availability your AWS infrastructure demands. Whether you’re looking to save costs, enhance performance, or both, the migration from GP2 to GP3 can be a valuable step in achieving your AWS storage goals.
Prerequisites:
- Create an IAM Role with EC2FullAccess permission to lambda which permits an lambda to access an EBS volume of an EC2 without any permission issues.
- Please take an AMI/Snapshots for an critical workloads.
Steps:
- Establish a Lambda function with Python 3.8 as the runtime programming language, and make sure to select the previously created role during the prerequisite setup.

- Please copy and paste the provided code into the Lambda function and then proceed to deploy the changes in Lambda by clicking the “Deploy” button.
import boto3
def lambda_handler(event, context):
Replace the volume ID’s with your actual values
volume_ids = [“vol-XXXXXXXX”] region = “ap-south-1”
ec2 = boto3.client(‘ec2’, region_name=region)
for volume_id in volume_ids: response = ec2.modify_volume(VolumeId=volume_id, VolumeType=’gp3') print(f”Volume {volume_id} modification started.”)
return “All volume modifications started.”
Example:
import boto3 def lambda_handler(event, context):
Replace the volume ID’s with your actual values
volume_ids = [“vol-0efc61b05410b277f”] region = “ap-south-1”
ec2 = boto3.client(‘ec2’, region_name=region)
for volume_id in volume_ids: response = ec2.modify_volume(VolumeId=volume_id, VolumeType=’gp3') print(f”Volume {volume_id} modification started.”)
return “All volume modifications started.”

- Extend the maximum runtime duration of a Lambda function to 15 minutes.

-
Initiate the Lambda function to begin the modification process for all the volume IDs specified in the code.
-
You can view the status of volume modifications by navigating to the “Volumes” section in the EC2 dashboard. The time it takes for a modification to complete can vary depending on the size of the volume.


- Volume modification completed successfully.

Pls, use the below code to automatically fetch the volume ID’s since in case of multiple volumes fetching an ID is an tedious task which can also be automated using below python code.
import boto3
def trigger_volume_modification(event, context): ec2 = boto3.client(‘ec2’, region_name=’ap-south-1') # Replace with your region
Use filters to narrow down the volumes you want to upgrade
filters = [ {‘Name’: ‘volume-type’, ‘Values’: [‘gp2’]}, # Replace with your criteria
Add more filters as needed
]
response = ec2.describe_volumes(Filters=filters) volume_ids = [volume[‘VolumeId’] for volume in response[‘Volumes’]]
ec2 = boto3.client(‘ec2’, region_name=’your-region’) # Replace with your region
for volume_id in volume_ids: response = ec2.modify_volume(VolumeId=volume_id, VolumeType=’gp3') print(f”Volume {volume_id} modification started.”)
return “Volume modification process initiated.”
Conclusion:
In conclusion, migrating EBS volume types from Gp2 to Gp3 in AWS can bring several benefits, including improved performance and cost optimization. Gp3 volumes offer higher IOPS per gigabyte, lower latency, and better throughput compared to Gp2 volumes. Additionally, Gp3 volumes allow you to adjust provisioned IOPS and throughput independently, giving you more flexibility to meet the specific needs of your applications.
However, before migrating, it’s crucial to carefully plan and execute the transition to minimize disruptions to your workloads. This involves identifying the volumes that would benefit from the migration, understanding the potential impact on your applications, and monitoring the progress of the migration process.
By following best practices and using AWS tools like AWS Lambda and the AWS Management Console, you can smoothly transition your EBS volumes from Gp2 to Gp3, improving the overall performance and cost-efficiency of your AWS infrastructure.
메타데이터
- post_id
- 2309b9044591
- slug
- aws-ebs-bulk-volume-modification-from-gp2-to-gp3-using-lambda-2309b9044591
- url
- https://medium.com/@gowthamusa.98/aws-ebs-bulk-volume-modification-from-gp2-to-gp3-using-lambda-2309b9044591
- canonical_url
- https://medium.com/@gowthamusa.98/aws-ebs-bulk-volume-modification-from-gp2-to-gp3-using-lambda-2309b9044591
- author_url
- https://medium.com/@gowthamusa.98
- status
- ok
- fetched_at
- 2026-06-29 01:02:39