DEV Community

irfan pasha
irfan pasha

Posted on

πŸš€AWS Lambda S3 File Upload Logger using Python

πŸš€ Project Overview

In this project, I implemented an AWS Lambda function using Python that automatically logs file upload details whenever a file is uploaded to an Amazon S3 bucket.

This project demonstrates real-time event-driven architecture using AWS services.

🧱 Architecture

Flow:

  1. File uploaded to S3 bucket
  2. S3 triggers AWS Lambda
  3. Lambda extracts file details
  4. Logs stored in CloudWatch

Services Used:

  • Amazon S3
  • AWS Lambda (Python)
  • Amazon CloudWatch

🐍 Lambda Function Code (Python)


python
def lambda_handler(event, context):
    record = event['Records'][0]
    bucket_name = record['s3']['bucket']['name']
    file_name = record['s3']['object']['key']
    file_size = record['s3']['object']['size']

    print(f"Bucket Name: {bucket_name}")
    print(f"File Name: {file_name}")
    print(f"File Size: {file_size} bytes")

πŸ“Š CloudWatch Logs Output

After uploading a file to the S3 bucket, the Lambda function logged:

Bucket Name

File Name

File Size

This confirms the function executed successfully.


https://github.com/IrfanPasha05/s3-file-upload-logger
Enter fullscreen mode Exit fullscreen mode

Top comments (0)