Serverless S3 File Processor using Shared Lambda Layer | AWS S3 Lambda Project
By Sowjanyashree N R
Published: July 01, 2025
Introduction
In cloud-native applications, processing files stored in Amazon S3 is a common requirement across a range of industries—from data analytics and document management to content pipelines and image processing. However, many real-world systems deal with more than just one file format. CSV logs, PDF documents, and image uploads often arrive at the same entry point, requiring format-specific processing.
Traditionally, developers either write monolithic code to handle all formats or duplicate file-handling logic across multiple services. This leads to brittle systems, poor maintainability, and difficulty scaling.
This project introduces a modular, event-driven file processing architecture designed to dynamically handle multiple file types in a serverless environment using AWS Lambda, Java 17, AWS SAM, and a shared Lambda layer. It centralizes reusable logic, avoids deployment pitfalls like circular dependencies, and ensures clean separation between components.
Project Objective
The primary objective of this system is to enable automated processing of different file types uploaded to S3 by delegating the handling of each format to a dedicated Lambda function. To avoid duplication and promote reuse, all file-processing Lambdas share a centralized utility layer for downloading and caching files.
A key architectural challenge arises when trying to configure S3 event notifications that target multiple Lambda functions using infrastructure-as-code tools like AWS SAM. This project resolves this by introducing a custom resource Lambda function that dynamically sets up S3 triggers during deployment, bypassing the circular dependency that often occurs between S3 and Lambda resources in a single stack.
Why This Approach?
Architecture Diagram
Prerequisites
To deploy and run this project, ensure the following prerequisites are met:
An AWS account with permissions to create and manage:
Installed tools:
Services Used
This project uses the following AWS services:
Working Flow Overview
File Upload to S3 Bucket
User uploads a file (e.g., .csv, .pdf, .jpg) to a designated folder (/input/) in the S3 bucket.
Recommended by LinkedIn
Automatic Trigger Based on File Type
S3 automatically triggers the appropriate processor Lambda function based on the file extension.
Processor Lambda Invokes Shared Lambda Layer
The triggered Lambda function uses a Shared Lambda Layer to download the file from S3 and cache it in /tmp
Format-Specific File Processing
Each processor performs logic specific to the file type (e.g., CSV row parsing, PDF text extraction, or image verification
Execution Logging and Cleanup
After processing, temporary files in the /tmp directory are deleted, marking the completion of execution.
Benefits of the Architecture
Conclusion
This project demonstrates a clean, extensible, and production-ready architecture for handling multi-format S3 file uploads in a serverless environment. It emphasizes separation of concerns, code reuse, and deploy ability through dynamic resource configuration and shared logic.
Designed using Java 17 and AWS best practices, it serves as a foundational blueprint for any cloud-native system that processes incoming files with format-specific logic.
Whether you are building a document ingestion pipeline, image classifier, or data ingestion framework, this architecture is a proven and reliable pattern worth adopting.
🔗 Explore the full project here: Serverless-S3-File-Processor-Using-Shared-Lambda-Layer
Great approach!
Good Approach! irl, Using Design patterns like combination of Strategy and Factory patterns will solve this problem, this is widely used in the industries as of now.