AWS Builder Center
Building a Serverless File Tracking System with AWS Lambda, Amazon S3, and DynamoDB

Building a Serverless File Tracking System with AWS Lambda, Amazon S3, and DynamoDB

Learn how to build an event-driven serverless architecture on AWS that automatically tracks uploaded files using Amazon S3, AWS Lambda, Amazon DynamoDB, and Amazon CloudWatch. This hands-on tutorial explores cloud automation, scalability, security, and cost optimization.

The future will be Cloud ☁️

Introduction

In today's cloud computing landscape, organizations are constantly seeking ways to build applications that are scalable, cost-efficient, and easy to maintain.
Traditional architectures often require developers to provision servers, manage infrastructure, configure scaling mechanisms, and maintain systems even when workloads are inactive.
Serverless computing offers a different approach.
With Amazon Web Services (AWS), developers can build event-driven applications that automatically respond to activities without managing traditional application servers.
Imagine a scenario where an organization receives hundreds or thousands of files through cloud storage. Instead of manually tracking every upload, a serverless architecture can automatically detect new files, process their metadata, and register information in a database.
In this article, we will explore how to build a Serverless File Tracking System using AWS Lambda, Amazon S3, Amazon DynamoDB, and Amazon CloudWatch.
By the end, you will understand how these services communicate, how to implement the solution, and how to apply serverless principles to real-world cloud environments.

1. What Is Serverless Computing?

Serverless computing is a cloud execution model in which the cloud provider manages much of the underlying infrastructure required to run applications.
Despite its name, serverless computing does not mean that servers no longer exist.
Instead, developers can focus on application logic while AWS manages infrastructure tasks such as provisioning, scaling, and maintaining the compute environment.
AWS provides several managed services that support serverless applications.
One of the most widely used is AWS Lambda.
Lambda allows developers to execute code in response to events without provisioning or managing servers.

Key Benefits of Serverless Computing

Automatic Scalability
Serverless applications can scale automatically based on incoming requests and events, subject to configured concurrency and service quotas.
Cost Efficiency
AWS Lambda follows a usage-based pricing model, meaning customers generally pay for requests and compute resources consumed rather than continuously running dedicated application servers.
Reduced Operational Complexity
Developers spend less time maintaining infrastructure and more time building application functionality.
Event-Driven Architecture
Applications can automatically respond to events generated by AWS services such as Amazon S3.
Cloud-Native Integration
Serverless services integrate with databases, monitoring solutions, messaging services, and other AWS infrastructure components.
These characteristics make serverless computing especially useful for automation, file processing, API backends, and data-driven applications.

2. Understanding the AWS Services Used

Our architecture combines four AWS services, each responsible for a specific part of the workflow.

Amazon S3 — Object Storage

Amazon Simple Storage Service (Amazon S3) is an object storage service designed for scalability, durability, availability, and security.
Organizations use Amazon S3 to store documents, images, application files, backups, logs, and other types of data.
For our project, Amazon S3 will act as the entry point for uploaded files.
Whenever a new object is created inside a specific location in the bucket, an event notification will be generated.
That event will trigger the next component in our architecture.

AWS Lambda — Event Processing

AWS Lambda is a serverless compute service that executes code in response to events.
It supports programming languages such as Python, JavaScript, Java, and other runtimes.
In this architecture, Lambda will be responsible for:
  • Receiving Amazon S3 event notifications.
  • Identifying newly uploaded objects.
  • Extracting file metadata.
  • Generating an event identifier.
  • Recording information in DynamoDB.
  • Reporting execution results.
The Lambda function runs only when invoked, eliminating the need for a continuously running application server.

Amazon DynamoDB — Metadata Storage

Amazon DynamoDB is a fully managed NoSQL database service designed to support applications requiring low-latency access and scalable performance.
In our solution, DynamoDB will store information about the uploaded files.
Examples include:
  • S3 bucket name.
  • Object key or file path.
  • File size.
  • Upload event timestamp.
  • Event identifier.
  • Processing timestamp.
The database will act as a structured record of the object creation events processed by our system.

Amazon CloudWatch — Monitoring and Observability

Amazon CloudWatch provides monitoring, logging, metrics, and operational visibility for AWS applications.
For our architecture, CloudWatch will help developers understand how the Lambda function behaves.
It can provide visibility into invocation counts, execution duration, errors, and application logs.
This is particularly important when troubleshooting failed executions or improving operational reliability.

3. Serverless Solution Architecture

Our application will follow a simple event-driven workflow.
File Upload → Amazon S3 → AWS Lambda → Amazon DynamoDB
Amazon CloudWatch will provide observability for the Lambda execution process.

How the Architecture Works

Step 1 — File Upload
A user or application uploads a file to an Amazon S3 bucket.
Step 2 — Event Notification
Amazon S3 detects the object creation and generates an event notification.
Step 3 — Lambda Invocation
The event notification invokes an AWS Lambda function.
Step 4 — Metadata Processing
Lambda extracts the bucket name, object key, size, and event timestamp.
Step 5 — Database Registration
Lambda writes the metadata into an Amazon DynamoDB table.
Step 6 — Monitoring
Amazon CloudWatch captures execution logs and operational metrics.
This architecture demonstrates how AWS services can communicate automatically without requiring developers to manage servers.
It also introduces the concept of loose coupling, where independent components interact through well-defined events and interfaces.

4. Prerequisites

Before implementing this tutorial, you should have:
  • An active AWS account.
  • Access to the AWS Management Console.
  • Basic familiarity with AWS Identity and Access Management (IAM).
  • Basic knowledge of Python.
  • Permissions to create Amazon S3 buckets, AWS Lambda functions, DynamoDB tables, and IAM roles.
This project uses a small demonstration workload, but AWS resources can generate charges.
Consider configuring AWS Budgets and reviewing the pricing of each service before starting.

5. Step-by-Step Implementation

Now that we understand the architecture, let's build the solution.

Step 1 — Create an Amazon S3 Bucket

  1. Open the AWS Management Console.
  1. Navigate to Amazon S3.
  1. Select Create bucket.
  1. Choose a globally unique bucket name, such as  serverless-file-tracker-your-unique-id .
  1. Select an AWS Region.
  1. Keep Block Public Access enabled.
  1. Create the bucket.
For this example, our files will be uploaded using the following object key prefix:
 uploads/ 
A sample object key will be:
 uploads/sample.csv 
This prefix will help us configure which uploaded objects should trigger Lambda.
Using a specific prefix also reduces the possibility of unintended event processing.

Step 2 — Create a DynamoDB Table

Next, create the database responsible for storing file event metadata.
  1. Open the Amazon DynamoDB console.
  1. Select Create table.
  1. Enter the table name  S3ObjectEvents .
  1. Configure the partition key as  event_id .
  1. Select the String data type.
  1. Choose the on-demand capacity option.
  1. Create the table.
The  event_id  attribute will uniquely identify each recorded object-created event.
This approach allows us to maintain a history of object creation events rather than simply overwriting a single record for each file.

Step 3 — Create the AWS Lambda Function

Navigate to AWS Lambda in the AWS Management Console.
Select Create function and configure:
Function name:  S3FileTracker 
Runtime: A currently supported Python runtime
Architecture:  x86_64 
Execution role: Create or select an IAM role with the necessary permissions.
For this tutorial, the execution role needs permission to write items to the DynamoDB table and publish execution logs to CloudWatch.
An IAM policy granting DynamoDB write access might look like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:PutItem"
],
"Resource": "arn:aws:dynamodb:REGION:ACCOUNT_ID:table/S3ObjectEvents"
}
]
}
Replace  REGION  and  ACCOUNT_ID  with the actual values from your AWS environment.
For CloudWatch logging, the role can use the AWS-managed  AWSLambdaBasicExecutionRole  policy.
Avoid granting unnecessary administrative privileges.

Step 4 — Configure the Environment Variable

Inside your Lambda function configuration, navigate to Environment variables.
Create the following variable:
Key:  TABLE_NAME 
Value:  S3ObjectEvents 
This allows the application to identify the correct DynamoDB table without hardcoding the table name directly into the source code.

Step 5 — Implement the Python Function

Open the Lambda code editor.
Replace the default function code with the following Python example:
import os
import hashlib
import boto3

from datetime import datetime, timezone
from urllib.parse import unquote_plus
from botocore.exceptions import ClientError

dynamodb = boto3.resource("dynamodb")

table = dynamodb.Table(
os.environ["TABLE_NAME"]
)

def lambda_handler(event, context):

processed = 0
duplicates = 0

for record in event.get("Records", []):

if record.get("eventSource") != "aws:s3":
continue

if not record.get("eventName", "").startswith(
"ObjectCreated:"
):
continue

bucket = record["s3"]["bucket"]["name"]

object_data = record["s3"]["object"]

object_key = unquote_plus(
object_data["key"]
)

file_size = object_data.get("size", 0)

event_time = record["eventTime"]

sequencer = object_data["sequencer"]

event_identifier = (
f"{bucket}|{object_key}|{sequencer}"
)

event_id = hashlib.sha256(
event_identifier.encode("utf-8")
).hexdigest()

item = {
"event_id": event_id,
"bucket": bucket,
"object_key": object_key,
"file_size": file_size,
"event_time": event_time,
"sequencer": sequencer,
"processed_at": datetime.now(
timezone.utc
).isoformat()
}

try:
table.put_item(
Item=item,
ConditionExpression=(
"attribute_not_exists(event_id)"
)
)

processed += 1

print(
f"Recorded file: {object_key}"
)

except ClientError as error:

error_code = error.response[
"Error"
]["Code"]

if error_code == (
"ConditionalCheckFailedException"
):
duplicates += 1

else:
raise

return {
"statusCode": 200,
"processed": processed,
"duplicates": duplicates
}

Understanding the Code

The implementation performs several important operations.
First, it initializes a DynamoDB resource using the AWS SDK for Python, Boto3.
The function reads the incoming Amazon S3 event notification and extracts information about the uploaded object.
It retrieves the bucket name, object key, file size, event timestamp, and event sequencer.
Next, it generates an event identifier using SHA-256. This provides a fixed-length key derived from the bucket, object key, and S3 sequencer.
The function then creates a DynamoDB item containing the extracted metadata.
A conditional write prevents the same event identifier from being registered multiple times.
This is important because Amazon S3 event notifications can occasionally be delivered more than once.
Finally, the function returns a summary of the number of processed and duplicate events.
Important: This is an educational implementation. It records object creation events but does not provide complete file lifecycle tracking, deletion monitoring, or guaranteed ordering of changes to the same object.

Step 6 — Configure the Amazon S3 Trigger

After saving and deploying the Lambda function, configure an S3 trigger.
  1. Open your Lambda function.
  1. Select Add trigger.
  1. Choose Amazon S3.
  1. Select the bucket created earlier.
  1. Choose the event type  s3:ObjectCreated:* .
  1. Set the prefix filter to  uploads/ .
  1. Confirm the configuration and add the trigger.
Ensure that the S3 bucket and Lambda function are located in the same AWS Region.
The S3 trigger configuration must also permit the bucket to invoke the Lambda function.
After completing this step, Lambda should automatically execute whenever a new object is created under the  uploads/  prefix.

Step 7 — Test the Application

Now we can validate the architecture.
Open your Amazon S3 bucket and upload a small test file with the following object key:
 uploads/sample.csv 
The expected workflow is:
  1. Amazon S3 receives the file.
  1. S3 generates an object-created event.
  1. AWS Lambda receives the notification.
  1. Lambda extracts the object metadata.
  1. DynamoDB stores the event record.
  1. CloudWatch captures execution information.
Navigate to your DynamoDB table and open the item explorer.
If the execution succeeds, you should see a new record containing the uploaded object's metadata.
For example, the item may include:
{
"bucket": "serverless-file-tracker-example",
"object_key": "uploads/sample.csv",
"file_size": 1024,
"event_time": "2026-11-03T15:00:00.000Z",
"sequencer": "006900000000000001",
"processed_at": "2026-11-03T15:00:01+00:00"
}
The values above are illustrative examples, not actual test results.
The real DynamoDB item will also include its generated  event_id .
If no record appears, review the Lambda logs in CloudWatch and verify the permissions, trigger configuration, and database name.

6. Understanding Event-Driven Architecture

One of the most important concepts demonstrated by this project is event-driven architecture.
Traditional applications sometimes check resources repeatedly to determine whether a change has occurred.
For example, a scheduled application might inspect an S3 bucket every few minutes to identify recently uploaded files.
With an event-driven design, the application does not need to continuously check for changes.
Instead, the storage service produces an event when an object is created.
That event initiates the processing workflow.
This model can improve responsiveness and reduce unnecessary processing.
It can also simplify the relationship between services because components communicate using events rather than continuously running monitoring loops.
However, event-driven applications must be designed to handle retries, duplicate events, and potential failures.

7. Security Best Practices

Security should be considered from the beginning of any cloud architecture.
Even a relatively simple serverless application interacts with several resources, including storage, compute, databases, and monitoring services.

Apply the Principle of Least Privilege

AWS IAM roles should grant only the permissions required for specific functions.
Our Lambda function needs permission to write to the designated DynamoDB table.
It does not need full administrative access to the AWS account.

Protect Stored Data

Amazon S3 buckets should remain private unless public access is explicitly required.
Encryption and access control policies should be configured according to organizational requirements.
DynamoDB also supports encryption at rest.
For sensitive business files, additional controls may be necessary, including data classification, retention policies, and access auditing.

Avoid Exposing Sensitive Information

Developers should avoid storing credentials directly in source code.
AWS IAM roles provide temporary credentials for authorized AWS service interactions.
Logs should also avoid including unnecessary personal or confidential information.

Design for Duplicate Events

Amazon S3 notifications follow an at-least-once delivery model.
This means that an event may occasionally be delivered multiple times.
Applications should be designed to process duplicate notifications safely.
Our implementation uses conditional DynamoDB writes to avoid duplicating records associated with the same generated event identifier.

Consider Event Ordering

S3 notifications are not guaranteed to arrive in the same order in which operations occurred.
The  sequencer  value can help determine the relative order of object events involving the same object key.
Production applications that maintain the latest object state should implement additional ordering controls.

8. Monitoring with Amazon CloudWatch

Monitoring is essential for understanding the reliability of serverless applications.
AWS Lambda integrates with Amazon CloudWatch to provide operational metrics and logs.
Developers can monitor several important indicators.
Invocations
The number of times the Lambda function executes.
Errors
The number of function invocations that result in errors.
Duration
The time spent executing the function.
Throttles
The number of invocations that are throttled due to concurrency limits.
Application Logs
Custom messages generated by the function during execution.
In our Python example, successful writes generate log messages indicating which file was registered.
For production environments, CloudWatch alarms can notify operations teams when application errors or other metrics exceed defined thresholds.
Lambda asynchronous invocation settings and failure destinations should also be reviewed to handle events that cannot be processed successfully.

9. Cost Optimization in Serverless Applications

One of the reasons organizations adopt serverless computing is the opportunity to align infrastructure costs with actual application usage.
However, serverless does not automatically guarantee lower costs.
Charges depend on workload patterns, configurations, and service usage.

AWS Lambda

Lambda pricing generally considers request volume and compute consumption.
Applications should avoid unnecessary invocations, excessive memory allocation, and inefficient execution.

Amazon S3

S3 costs can include data storage, requests, data transfer, and other features depending on usage.
Choosing appropriate storage classes and lifecycle policies can help optimize expenses.

Amazon DynamoDB

DynamoDB on-demand pricing can be suitable for variable or unpredictable workloads.
Application designers should consider storage requirements, access patterns, and write volume.

Amazon CloudWatch

CloudWatch costs can depend on logging volume, retention, monitoring features, and other usage.
Log retention should be configured according to operational and compliance requirements.

General Recommendations

  • Monitor monthly AWS spending.
  • Configure AWS Budgets and cost alerts.
  • Avoid unnecessary Lambda executions.
  • Apply appropriate log retention policies.
  • Review database capacity and application access patterns.
  • Delete unused testing resources.
The goal is not simply to reduce infrastructure costs, but to achieve an appropriate balance between performance, reliability, security, and financial efficiency.

10. Real-World Business Applications

The architecture demonstrated in this tutorial can be adapted to multiple business scenarios.

Document Management

Organizations can automatically register metadata whenever new documents are uploaded to centralized storage.
This can support document inventories, operational tracking, and automated workflows.

Financial File Processing

Financial departments often receive structured files containing transactions, reports, and reconciliation information.
A serverless workflow can detect new files and initiate validation or processing activities.

Data Engineering Pipelines

Data engineering teams can use S3 events to initiate data processing activities whenever new datasets arrive in cloud storage.
Additional services can transform, validate, and move data between systems.

Operational Reporting

Organizations can automatically track files generated by internal applications or external integrations.
This can provide better visibility into data movement and processing activities.

Audit and Compliance Support

File event tracking can contribute to operational traceability.
However, an application-level event database should not be considered a substitute for comprehensive security auditing.
Services such as AWS CloudTrail may be required to record relevant API activity and support broader audit requirements.

11. Expanding the Architecture

The implementation presented in this article is intentionally simple.
As requirements evolve, the architecture can integrate additional AWS services.
Amazon EventBridge
EventBridge can support more advanced event routing and integration between cloud services.
Amazon Simple Queue Service (SQS)
Amazon SQS can provide a message buffer between event producers and processing services, improving resilience during traffic spikes.
AWS Step Functions
Step Functions can coordinate multi-step workflows involving validation, processing, enrichment, and notifications.
Amazon API Gateway
API Gateway can expose application capabilities through managed APIs.
AWS CloudTrail
CloudTrail can provide visibility into supported AWS API activity and help strengthen auditability.
For larger workloads, developers should evaluate reliability requirements, failure handling, concurrency management, and operational complexity before expanding the design.

12. Key Lessons Learned

This project demonstrates several important principles of modern AWS cloud architecture.
First, managed services allow developers to build applications without maintaining traditional application servers.
Second, event-driven architectures make it possible to automate business processes when relevant events occur.
Third, the integration between Amazon S3, AWS Lambda, and DynamoDB provides a straightforward approach to metadata processing and storage.
Fourth, serverless systems still require thoughtful security, monitoring, and reliability controls.
Finally, cloud architecture should always be designed with scalability, operational efficiency, and cost awareness in mind.
Understanding these concepts provides a solid foundation for developing more advanced cloud-native applications.

Conclusion

Serverless computing represents an important approach to modern cloud application development.
By combining Amazon S3, AWS Lambda, Amazon DynamoDB, and Amazon CloudWatch, developers can build an automated file tracking workflow using managed AWS services.
The architecture presented in this article demonstrates how a simple file upload can trigger an entire processing workflow without requiring a continuously running application server.
Beyond the technical implementation, the project introduces essential cloud engineering principles, including event-driven processing, least-privilege access, idempotency, monitoring, and cost optimization.
These concepts can be applied to numerous real-world scenarios, from document management and financial automation to data engineering and operational workflows.
As cloud environments continue to evolve, understanding serverless architecture will remain valuable for developers, cloud engineers, and technology professionals looking to create scalable and maintainable solutions.
What business process would you automate using AWS Lambda and Amazon S3?



References

The following official AWS resources provide additional technical guidance:
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article