Using AWS CloudWatch and Lambda, we automate resource management by triggering Lambda functions upon Amazon EBS volume creation. Leveraging CloudWatch Events, we monitor GP2 EBS volumes, seamlessly converting them to GP3 for enhanced performance.
step 1:- Create an lambda function as ‘ebs_volume_check’ and runtime as ‘python 3.10’ also we Create a new role with basic Lambda permissions.
after creating an lambda function just test it so we confirm that lamda fuction is work correctly.
step 2 :- Go to cloudwatch service then go to event section and create an role for the ebs volume creation. Select service name as ec2 , Event type is EBS Volume Notification ,specific event is createVolume. In target section we select existing lambda fuction and configure details.
give name as per your requirement and creating role.
step 3 :- go to Ec2 service underneath we select as volume section and create an volume and create gp2 ebs volume).
step 4 :- go to log groups of cloudwatch service we see the lambda fuction is triggered.
add following code to lambda function
and remove the ebs volume that we created and again recreate the ebs volume so that lambda fuction is automatically triggered and we get an detailed logs about the ebs volume.
step 5 :- Go to IAM service and create an inline policy for that role , select service as ec2 and for actions allowed we select ‘volume’ and for that we add ‘describe volume’ and ‘modify volume’ and create policy.
step 6 :- so we can write an final lambda fuction as below ,
and remove the ebs volume that we created and again recreate the ebs volume so that lambda fuction is automatically triggered.so finally we see the output as ebs volume is converted to gp2 to gp3 type.