Explore of Lambda Versions Deletion Using Lambda Function
Tags: aws, awslambda, iamrole, serverless
Published: 2023-05-13 09:42:31

“ I have checked the documents of AWS to delete the lambda function versions in one run instead of manually deleting each version of a function. Got a solution to delete the lambda versions using lambda function by code run. In terms of cost, the solution is cheaper and secure.”

Lambda is a compute service that lets you run code without provisioning or managing servers. Lambda runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring and logging. With Lambda, you can run code for virtually any type of application or backend service.

In this post, you will experience the lambda versions deletion using lambda function. Here I have created a lambda function with versions and IAM role with required permissions.

#Prerequisites
You’ll need an AWS Lambda for this post. [Getting started with aws Lambda](https://aws.amazon.com/lambda/getting-started/) provides instructions on how to create a lambda function. For this blog, I assume that I have a lambda function and IAM role created.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n33745xfcwxk4jqebtb1.png)
The architecture diagram shows the overall deployment architecture with data flow, lambda and iam role.

#Solution overview
The blog post consists of the following phases:
1. Create of Lambda Function for Deleting the Lambda Version
2. Testing of Lambda Version Deletion

I have a lambda function with versions and IAM role with required permission created as below →
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xfx1vmkk83llqm4xvxgk.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rvlog4xtf7nkkmkjlhf.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xz2rxmxnn3q8rfiwnp74.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2zfd1ifcvmlp3tfsvxr.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c149vy010k1qa9zoyf8c.png)

##Phase 1: Create of Lambda Function for Deleting the Lambda Version
1. Open the console for AWS lambda and create a lambda function as delete-lambda-version with function code.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfpjzl12lnyvnp5mi9z3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdx7drb1fvfex4scpdut.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s27smivpzevapfvwpuge.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mirw559zvkmp85uqf1fi.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kqc5tkco2425q1787xc.png)

##Phase 2: Testing of Lambda Version Deletion

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nbsed0shz1j91p45hc4z.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lfm195tq9b3c1a1am5mw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgniwao715k622uo9yri.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3y4bu5cong22rw83of6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/btexsgsur9idcd11jjt7.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p7yklr12dg0897037nup.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agr1qfj49h0kh30ftgol.png)

#Clean-up
Delete of IAM, lambda and cloudwatch log group.

#Pricing
I review the pricing and estimated cost of this example. 

Cost of Cloudwatch = $0.0

Cost of Lambda = $0.0

Total Cost = $(0.0 + 0.0) = $0.0

#Summary
In this post, I showed “explore of lambda versions deletion using lambda function”.

For more details on AWS Lambda, Checkout Get started AWS Lambda, open the [AWS Lambda console](https://ap-south-1.console.aws.amazon.com/lambda/home?region=ap-south-1#/discover). To learn more, read the [AWS Lambda documentation](https://docs.aws.amazon.com/lambda/?id=docs_gateway).

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)