AWS Builder Center

Building a Serverless Image Processing Pipeline with Amazon S3, AWS Lambda, and Amazon DynamoDB

Learn how to build a serverless image processing workflow using Amazon S3, AWS Lambda, and Amazon DynamoDB, including upload events, metadata tracking, and reliable processing.

Introduction

Modern applications often need to process images after users upload them. An application may need to validate an image, extract information, track processing status, or prepare the image for additional workflows.
Instead of maintaining dedicated servers for these tasks, we can build an event-driven serverless pipeline using Amazon S3, AWS Lambda, and Amazon DynamoDB.
The basic workflow is:
User → Amazon S3 → AWS Lambda → DynamoDB
When an image is uploaded to Amazon S3, an event automatically triggers a Lambda function. Lambda processes the event and stores information about the uploaded image in DynamoDB.

Architecture

The solution uses three main AWS services:
  • Amazon S3 – Stores uploaded images.
  • AWS Lambda – Processes S3 upload events.
  • Amazon DynamoDB – Stores image metadata and processing status.
The workflow can be represented as:
1
2
3
4
5
6
7
8
9
10
11
12
13
User
|
| Upload Image
v
Amazon S3
|
| Object Created Event
v
AWS Lambda
|
| Store Metadata
v
Amazon DynamoDB
This event-driven architecture allows the application to react automatically whenever a new image is uploaded.

1. Store Images in Amazon S3

The first step is to create an S3 bucket for storing uploaded images.
For example:
1
my-image-processing-bucket
Uploaded files can be organized using prefixes:
1
2
3
uploads/profile/photo1.jpg
uploads/products/product1.png
uploads/documents/document1.jpg
Using prefixes helps keep different types of uploaded content organized.
For production applications, the bucket should use appropriate security controls such as Block Public Access and encryption.

2. Configure an S3 Event

Amazon S3 can generate an event whenever a new object is created.
For example, an application can use the ObjectCreated event to trigger a Lambda function.
The workflow becomes:
1
2
3
4
5
6
7
Image uploaded
|
v
S3 ObjectCreated event
|
v
Lambda function starts
This means the application does not need to continuously check the S3 bucket for new files.

3. Process the Event with AWS Lambda

The Lambda function receives information about the uploaded object through the S3 event.
A simplified Python example is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import json

def lambda_handler(event, context):
record = event["Records"][0]

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

print(f"Processing image: {key}")
print(f"Bucket: {bucket}")

return {
"statusCode": 200,
"body": json.dumps("Image processed successfully")
}
The function can extract information such as:
  • S3 bucket name
  • Object key
  • Uploaded file information
The Lambda function can then perform additional validation or processing depending on the application's requirements.

4. Store Metadata in DynamoDB

After processing the uploaded image, we can store its metadata in a DynamoDB table.
For example, an image record could contain:
1
2
3
4
5
image_id
object_key
bucket_name
uploaded_at
processing_status
A simple example could look like:
1
2
3
image_id: IMG001
object_key: uploads/photo1.jpg
status: COMPLETED
DynamoDB provides a scalable way to maintain records associated with uploaded images.

5. Track Processing Status

Tracking processing status is useful when users need to know whether an uploaded image has been successfully processed.
A simple status flow could be:
1
2
3
4
5
6
7
UPLOADED
|
v
PROCESSING
|
v
COMPLETED
If processing fails, the application can record:
1
2
3
4
PROCESSING
|
v
FAILED
This provides visibility into the processing lifecycle and makes it easier to identify failed operations.

6. Handling Processing Failures

Serverless applications should also consider what happens when processing fails.
Possible causes include:
  • Invalid image data
  • Missing permissions
  • Unexpected application errors
  • Temporary service failures
  • Function timeout
For workloads that require buffering and controlled retries, Amazon SQS can be introduced between the event source and processing Lambda.
The architecture can then become:
1
2
3
4
5
6
7
8
9
10
Amazon S3
|
v
Amazon SQS
|
v
AWS Lambda
|
v
Amazon DynamoDB
This approach can help decouple image uploads from processing and provide additional control over retries.

7. Security Considerations

Security should be considered when designing the pipeline.
The Lambda execution role should follow the principle of least privilege. The function should only receive the permissions required to perform its tasks.
For example, Lambda may need permission to:
  • Read required objects from S3
  • Write records to DynamoDB
  • Write logs to Amazon CloudWatch
The S3 bucket should remain private unless public access is specifically required.
Encryption should also be enabled to help protect stored data.

8. Monitoring the Pipeline

Amazon CloudWatch can be used to monitor Lambda execution and identify errors.
Useful monitoring information can include:
  • Lambda invocations
  • Execution duration
  • Errors
  • Throttles
  • Log messages
Monitoring helps developers understand how the pipeline is performing and quickly identify processing failures.

9. Possible Enhancements

The basic pipeline can be extended as application requirements grow.
For example:
  • Amazon Rekognition can be added for image analysis.
  • Amazon SQS can provide buffering and retry handling.
  • Amazon CloudWatch can provide monitoring and logging.
  • Additional Lambda functions can generate thumbnails or validate images.
  • Notifications can be added to inform users when processing is completed.
An extended architecture could look like:
1
2
3
4
5
6
7
8
9
10
11
Amazon S3
|
v
AWS Lambda
/ \
/ \
v v
DynamoDB Rekognition
|
v
Application
This architecture can support use cases such as profile-image processing, e-commerce applications, document management systems, and media applications.

Benefits of the Serverless Approach

This architecture provides several benefits.

Automatic scaling

AWS Lambda can automatically handle multiple events without requiring developers to manually provision servers.

Reduced infrastructure management

There are no servers to patch or maintain for the image-processing layer.

Event-driven processing

Processing begins when an image is uploaded instead of requiring a continuously running application.

Flexible architecture

Additional AWS services can be added as the application grows.

Cost efficiency

With serverless services, resources are generally consumed based on actual usage rather than requiring continuously running compute infrastructure.

Conclusion

A serverless image processing pipeline can be built using Amazon S3, AWS Lambda, and Amazon DynamoDB.
Amazon S3 provides scalable object storage, AWS Lambda provides event-driven processing, and DynamoDB provides a flexible way to track image metadata and processing status.
The architecture removes the need to maintain dedicated servers while allowing applications to automatically respond to new image uploads.
As requirements grow, services such as Amazon SQS, Amazon Rekognition, and Amazon CloudWatch can be introduced to improve reliability, image analysis, and monitoring.
Starting with a simple event-driven architecture provides a strong foundation for building scalable and maintainable image-processing applications on AWS.
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