Skip to main content

Command Palette

Search for a command to run...

AWS Lambda :: Part 2

Updated
•2 min read•View as Markdown
AWS Lambda :: Part 2

USE-CASE :: Cost optimisation

This use case if used to check if you have any stale Snapshot in your AWS account and delete it . So that Python script checks the which volume and snapshot is present and then, if that snapshot is attached to any volume , if that then Lambda function delete that

Link for the python script

https://github.com/ApurvDevops/AWS/tree/master/cost-optimzation

Steps

  1. Create EC2 Instance

Associated Volume

  1. Take a Snapshot of the Volume associated with EC2 Instance
  1. Create a Lambda Function and add the required IAM Roles ( DescribeInstance, DescribeSnapshot, Deletesnapshot,DescribeVolume )

Failed because of Insufficient permission

Added the Policies as mentioned on above steps DescribeInstance, DescribeSnapshot, Deletesnapshot,DescribeVolume. Also Increase the Timeout to 10 secconds default timeout is 3 sec

Increased it to 10 Seconds.

Lambda Function ran successfully, but snapshot is still there

  1. Delete the EC2 Instance and then run the lambda function again.

Only Snapshot is there, now runt the function again manually

5) Extended Trails

You can even try to create a Volume create a snapshot of this, and try to run the function again. and again run the Lambda function, and see the result

Thanks for reading, if you reached till here, please try to implement this simplest lab , cheers !!!

aws-cloud

Part 15 of 24

Welcome to my dedicated AWS writing domain. Here, I break down cloud architecture, serverless systems, DevOps best practices, and practical AWS tutorials. This series centralizes all my cloud infrastructure deep dives into one unified space to help you build scalable and secure cloud applications.

Up next

AWS Lamdba :: Part 3

Use case 1 : Use Event Bridge, and Check if anyone is creating GP3 volume instead of GP2, then because of this Event , a Lambda function should trigger and it should delete entire GP3 volume. 1 ) Go t