image.png

Automating File Type Detection with Amazon S3 Event Triggers and AWS Lambda

Overview

This project implemented an event‑driven architecture where Amazon S3 automatically invoked an AWS Lambda function upon new file uploads, enabling real‑time detection and logging of file types. The aim was to demonstrate how serverless services can be combined to streamline operational workflows without relying on manual intervention or continuously running infrastructure.

The Challenge

Organizations often require near‑instant processing of incoming files, whether for validation, classification, or transformation. Traditional polling‑based systems can be inefficient, consuming unnecessary resources and introducing latency. The challenge here was to design a lightweight, cost‑effective, and scalable mechanism that could execute logic as soon as new objects were ingested, without manual checks or scheduled jobs.

The Approach

The solution leveraged S3’s native event notification capability to trigger a Lambda function written in Python. Lambda’s serverless model ensured that compute resources were only used when needed, while CloudWatch Logs provided visibility into each event. By structuring the workflow around AWS‑native integrations, the solution benefited from low operational overhead and high reliability.

Tools Used

The Execution

  1. I created a new Amazon S3 bucket in the default AWS region, keeping block public access enabled to maintain a secure, private storage layer since no files needed public exposure.

  2. In the AWS Lambda service, I built a function using the Python 3.12 runtime, selecting this version for its modern features and compatibility with current AWS environments. Within the Lambda function code, I implemented a script that parsed the event payload from S3, extracted the object key, determined the file extension, and wrote a log entry containing the detected file type, enabling straightforward auditing through CloudWatch Logs.

    image.png

  3. I configured an S3 trigger for the Lambda function, specifying the bucket as the source and setting the event type to PUT operations so the function would run whenever a new file was uploaded. This configuration also automatically created the necessary permissions for S3 to invoke the function.

    image.png

    image.png

  4. With the workflow deployed, I tested its responsiveness by uploading multiple files with different extensions such as .png and .txt to the bucket, confirming each triggered a Lambda invocation.

  5. I examined the CloudWatch Logs generated by the Lambda executions, verifying that each log correctly recorded the uploaded file’s detected type, demonstrating that the workflow operated reliably and consistently across file formats.

    image.png