Skip to main content

Command Palette

Search for a command to run...

AWS Lambda Functions: Empowering Serverless Computing and Automating S3 Bucket Cleanup

Published
โ€ข3 min read
AWS Lambda Functions: Empowering Serverless Computing and Automating S3 Bucket Cleanup
P

๐Ÿ‘‹ Hello! I'm passionate about DevOps and have over 1+ years of experience in the field. I'm proficient in a variety of cutting-edge technologies and always motivated to expand my knowledge and skills. Let's connect and grow together!

SKILLS:

๐Ÿ”น Languages & Runtimes: Python, Shell Scripting, HCL, YAML ๐Ÿ”น Cloud Technologies: AWS, Microsoft Azure, GCP ๐Ÿ”น Infrastructure Tools: Docker, Terraform, AWS CloudFormation ๐Ÿ”น Other Tools: Linux, Git and GitHub Actions, Jenkins, Jira, GitLab (beginner), Docker, AWS DevOps ๐Ÿ”น Web Development: HTML, CSS, Bootstrap, Python, SQL

Job & Responsibilities:

๐Ÿš€ Improved development efficiency by implementing CI/CD pipelines, resulting in a 30% reduction in deployment time on the test server. ๐Ÿ”’ Strengthened deployment and testing reliability by utilizing Docker containers and optimizing Dockerfile, reducing development issues on the test server by 20%. โš™๏ธ Automated S3 bucket log creation with Shell scripting, eliminating 100% of manual search and saving 2 hours per week. ๐Ÿ“… Scheduled EC2 instance start/stop using Lambda functions and Event Bridge, leading to a 25% decrease in infrastructure costs. ๐Ÿ”ง Utilized AWS, Linux, Python, Docker, Shell scripting, Terraform, Jenkins Pipelines, and automation to streamline workflows and improve overall system performance.

I'm very detail-oriented and possess strong written and verbal communication skills. As a high performer with a possibility mindset, I strive to solve problems using efficient approaches.

Let's Connect & Grow:

If you find my profile suitable for the role you are searching for, please feel free to reach out to me at sumanprasad9766@gmail.com.

๐Ÿ“Introduction:

AWS Lambda functions revolutionize serverless computing by offering an efficient and scalable solution for executing code without the need for managing servers. In this blog post, we will explore what AWS Lambda functions are, the problems they solve, and why they are valuable. We will then walk through a step-by-step process, complete with emojis and bullet points, to create a Lambda function that automatically deletes S3 buckets older than 90 days. Let's dive in and uncover the power of AWS Lambda!

What is an AWS Lambda Function and Why is it Valuable? ๐Ÿ”ง An AWS Lambda function is a serverless computing service provided by Amazon Web Services. ๐Ÿ’ก It allows you to run your code without the need to provision or manage servers, resulting in reduced operational overhead and improved scalability. ๐ŸŒŸ AWS Lambda functions are event-driven, executing in response to specific triggers or events. ๐ŸŒ By leveraging Lambda, developers can focus on writing code and let AWS handle the infrastructure management, enabling faster development and deployment cycles.

๐Ÿ” Real-Life Examples:

  1. ๐Ÿ“ธ Imagine a photo-sharing application where users upload images. With AWS Lambda, you can automatically generate thumbnails for these images as soon as they are uploaded, without the need to maintain a dedicated server for this purpose.

  2. ๐Ÿš€ In a social media platform, you can utilize Lambda to process and analyze user interactions, such as likes, comments, and shares, in real-time, allowing you to trigger personalized notifications or updates for the users.

  3. ๐Ÿ›’ E-commerce websites often need to process order updates or send confirmation emails to customers. Lambda functions can be employed to handle these tasks in a scalable and cost-efficient manner, without the need for constantly running servers.

๐Ÿ” Step-by-Step Process:

Creating a Lambda Function to Delete S3 Buckets Older Than 90 Days: ๐Ÿ”ง Set up the AWS Management Console and navigate to the Lambda service.

  1. ๐Ÿ–ฑ๏ธ Click on "Create function" and select "Author from scratch."

  2. ๐Ÿ“ Provide a name and choose the desired runtime for your Lambda function.

  3. ๐Ÿ”’ Configure the appropriate permissions by selecting an existing execution role or creating a new one with S3 access.

  4. ๐ŸŽ‰ Click on "Create function" to proceed to the function's configuration page.

โœ๏ธ Writing the Code:

  1. โœ๏ธ In the function's code editor, write the code to delete S3 buckets older than 90 days. Here's an example using Python and the Boto3 library:
import boto3
from datetime import datetime, timedelta

def lambda_handler(event, context):
    s3 = boto3.client('s3')
    response = s3.list_buckets()

    for bucket in response['Buckets']:
        bucket_name = bucket['Name']
        bucket_creation_date = bucket['CreationDate']
        if bucket_creation_date < datetime.now() - timedelta(days=90):
            s3.delete_bucket(Bucket=bucket_name)
  1. ๐Ÿ’พ Save the Lambda function after writing the code.

๐Ÿงช Testing the Function:

  1. โ–ถ๏ธ Test the function by configuring a test event or manually triggering it to ensure it behaves as expected.

๐Ÿ”„ Setting up the Trigger:

  1. โš™๏ธ To schedule the Lambda function to run periodically, create a CloudWatch Event Rule:

    • Click on "Add Trigger" in the function's configuration page.

    • Select "CloudWatch Events" as the trigger source.

    • Configure the event rule to trigger the Lambda function at the desired interval (e.g., daily).

    • Save the trigger configuration.

๐Ÿ“ Conclusion:

That's it! You have successfully created a Lambda function that will delete S3 buckets older than 90 days when triggered. The power of AWS Lambda allows you to automate tasks, reduce operational overhead, and enjoy the benefits of serverless computing. Embrace the flexibility and scalability of Lambda functions, and let AWS manage the infrastructure while you focus on building innovative solutions!

๐Ÿ” Checkout GitHub Repository for projects:

๐Ÿ”— https://github.com/sumanprasad007

More from this blog

D

DeployToCloud

405 posts

๐Ÿ‘‹ Welcome to my Hashnode blog! I'm a DevOps Engineer with 2+ years of experience. Join ~5k followers and explore 320+ blogs on Python, AWS, Docker, Jenkins, Linux, and more. Let's connect & grow ๐Ÿš€