Serverless with AWS Lambda

🌱 Just a fresher, vibin’ through tech life. ☁️ Cloud & DevOps rookie, tryna get my hands dirty with real stuff. 🛠️ Writing blogs in my own chill style ’cause most guides feel way too pro-level. 🚀 Learning, breaking, fixing, and sharing my journey—no sugarcoat, just raw curiosity.
Hello people, I’m back with my blog again! In the world of DevOps, the keyword serverless hits differently. But what does that actually mean? Does it mean there’s no server at all? If there’s no server, then how is our application being executed? Is some kind of external magic like om boom happening in the background?
Let’s learn today. As part of my learning process, I came across a service in AWS called Lambda. Lambda represents serverless computing and belongs to the compute family. So why wait? Let’s dive in and see what it actually means.
A Simple Scenario
Suppose our organization’s compliance requires us to use gp3 instead of gp2. If someone uses gp2, we usually check it manually. To automate, we might write a shell script, run it on an EC2 instance, and after completion, delete that instance.
But what if I told you we could become even lazier and do nothing — just like the tagline “Eat a 5 Star, do nothing”? Instead, we can hand this work over to another AWS service, configure it, and let it do the job for us at a specific time. Sounds crazy and lazy, right? Yes, we can do that with Lambda!
Basically, Lambda is event-driven. We can set up CloudWatch with a cron job at a specific time to trigger the Lambda function. The Lambda function will then create compute resources for us, run the required action, check if any gp2 volumes exist, and if yes, it will either send a notification to the developer or delete them. After the work is done, Lambda automatically tears everything down.
If required, during this process, it will automatically scale up or down. In EC2, we specify the instance type, RAM, and other details. But with Lambda, everything is created automatically based on the application’s needs, making us more productive (and a bit lazy too!).
Building a Project with AWS Lambda
Now let’s build a simple project together.
Aim-This Lambda function will delete a snapshot if:
It is not associated with any volume, or
It is associated with a volume, but that volume is not attached to any EC2 instance.
Steps
Repo – Copy the code from my GitHub repo (or fork it).
Login to AWS Console – Go to the Lambda function page.
Create a Lambda Function – Choose Python as the runtime (since we’ll be using boto3 here).
Set Permissions –
Go to Permissions.
Click on the service role.
Attach a policy that you create.
Select EC2, and in the search bar, give these permissions:
DescribeInstancesDescribeVolumesDescribeSnapshotsDeleteSnapshot
Attach this policy to the role.

Update General Configuration – Change execution time to 10 seconds only (don’t go beyond, as AWS charges for execution time).
Code Section – Paste the code from GitHub, then Save and Deploy.
Testing –
Create an instance and take a snapshot of its volume.
Now create a new test event and run it.
Output: Since the snapshot is associated with a volume and that volume is attached to the EC2 instance, the snapshot won’t be deleted.

Delete the Instance – Now delete the instance and test again.
Output: The snapshot still exists, but since its volume and instance are deleted, the function will now detect it and delete the snapshot.

Run the test and you’ll see:
The snapshot got deleted.
Now there are no snapshots left.


Conclusion
That’s the power of AWS Lambda — event-driven, automated, scalable, and cost-efficient. Instead of spinning up servers manually, we can automate tasks like compliance checks, cleanups, and more with just a bit of code and configuration.
Serverless doesn’t mean no servers; it just means you don’t have to manage them. AWS does the heavy lifting, and we just sit back, maybe eat a 5 Star, and let Lambda do the magic.
Hope you like it :)



