Lambda Triggers: S3 Events and DynamoDB Integration
By the end of this lesson, you'll be able to:
- Trace an S3 event-driven Lambda flow from upload to processed result
- Explain why event-driven functions should be designed to be idempotent
- Design a Lambda execution role scoped to only the S3 and DynamoDB permissions a function actually needs
Prerequisites: "API Gateway and Event-Driven Architecture"
S3 as an event source
Recall Module 4's S3 buckets and objects. S3 can be configured to raise an event whenever an object is created (or, depending on configuration, other object-level changes) — and that event can invoke a Lambda function automatically.
A realistic use case: a document- or image-processing pipeline, where uploading a file automatically triggers metadata extraction, a thumbnail, or a validation step — all without a server sitting idle, waiting for the next upload.
Idempotency: handling a redelivered event safely
This is one of the most important practical concepts in event-driven serverless design: an event can sometimes be delivered more than once. If processing the same event twice would produce a different (and wrong) result — creating two records instead of one, for example — that function has a real bug waiting to happen.
A function is idempotent when processing the same event multiple times produces the same end result as processing it once. A simple, common technique: check whether the specific item this event refers to has already been processed (for example, using the object's key, or an ID embedded in the event) before repeating the work. This lesson introduces the concept at a beginner level — the point isn't building a complete idempotency framework, it's recognizing that "this event might arrive twice" is a real design constraint, not an edge case worth ignoring.
Connecting to DynamoDB: building on Module 5
Many event-driven Lambda functions read from or write to DynamoDB (Module 5) as part of their processing — recording that a file was processed, storing extracted metadata, or looking up related data by a partition key. The same DynamoDB design guidance from Module 5 still applies here: know the access pattern this function actually needs (a specific lookup by key, or a specific write) before designing the table, rather than treating DynamoDB as a generic drop-in for any storage need.
Scoping the execution role narrowly
A function that reads from S3 and writes to DynamoDB needs an execution role (Module 2's least-privilege principle, applied to Lambda) granting exactly those two things — nothing wider.
Exercise
An S3-triggered Lambda function extracts metadata from uploaded images and writes one record per image to a DynamoDB table. The same upload event is occasionally delivered twice by AWS. (1) What could go wrong if the function isn't designed to handle this? (2) Describe one simple technique that would make the function idempotent. (3) What two specific permissions should its execution role grant, and nothing more?
Show hint
For (2), think about checking whether this specific image has already been processed before repeating the work. For (3), match the permissions to exactly what the function does: read from S3, write to DynamoDB.
Lambda Triggers: S3 Events and DynamoDB Integration Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
S3 can invoke a Lambda function whenever an object is uploaded, and the same function commonly reads from or writes to DynamoDB as part of its processing — but because an event can sometimes be delivered more than once, this kind of function should be designed to be idempotent, and its execution role should grant only the specific S3 and DynamoDB permissions it actually needs.