0
0
AWScloud~10 mins

Lambda with S3 event triggers in AWS - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Lambda with S3 event triggers
File uploaded to S3 bucket
S3 detects event: ObjectCreated
S3 sends event notification
Lambda function triggered
Lambda executes code
Process file or metadata
Lambda finishes execution
When a file is uploaded to an S3 bucket, S3 detects the event and sends a notification that triggers a Lambda function. The Lambda runs code to process the file or its metadata.
Execution Sample
AWS
1. Upload file to S3 bucket
2. S3 triggers Lambda on ObjectCreated
3. Lambda runs handler(event)
4. Lambda processes event data
5. Lambda completes execution
This sequence shows how uploading a file to S3 triggers a Lambda function that processes the event.
Process Table
StepActionEvent DataLambda StateOutput/Result
1File uploaded to S3 bucketObjectCreated event with file infoIdleS3 detects new object
2S3 sends event notificationEvent sent to Lambda triggerIdleLambda receives event
3Lambda function triggeredEvent passed to handlerRunningLambda starts processing
4Lambda processes event dataReads file info from eventRunningProcesses or logs file details
5Lambda finishes executionProcessing completeIdleReturns success or error
6Wait for next eventNo eventIdleLambda waits for next trigger
💡 Lambda finishes execution after processing the S3 event triggered by file upload
Status Tracker
VariableStartAfter Step 1After Step 3After Step 4Final
eventnullObjectCreated event with file infoSame event passed to handlerEvent data processednull after execution
Lambda StateIdleIdleRunningRunningIdle
Key Moments - 3 Insights
Why does Lambda start running only after the file upload?
Because S3 sends an event notification only when a new object is created, triggering Lambda as shown in execution_table step 2 and 3.
What does the Lambda 'event' variable contain?
It contains details about the S3 object created, such as bucket name and file key, as seen in execution_table step 1 and 4.
Why does Lambda return to Idle state after execution?
Lambda functions are stateless and run only when triggered; after processing, they stop running and wait for the next event, shown in step 5 and 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the Lambda State at Step 3?
ARunning
BIdle
CError
DWaiting
💡 Hint
Check the 'Lambda State' column at Step 3 in the execution_table.
At which step does S3 send the event notification to Lambda?
AStep 1
BStep 4
CStep 2
DStep 5
💡 Hint
Look for the action 'S3 sends event notification' in the execution_table.
If no file is uploaded to S3, what happens to Lambda's state?
ALambda runs continuously
BLambda stays Idle waiting for events
CLambda throws an error
DLambda deletes the S3 bucket
💡 Hint
Refer to the final step in execution_table where Lambda waits for the next event.
Concept Snapshot
Lambda with S3 event triggers:
- Uploading a file to S3 triggers an ObjectCreated event.
- S3 sends this event to Lambda as a trigger.
- Lambda runs code using event data (file info).
- After processing, Lambda stops and waits for new events.
- This enables automatic processing on file uploads.
Full Transcript
When you upload a file to an S3 bucket, S3 detects this new object creation and sends an event notification. This notification triggers a Lambda function. The Lambda function receives the event data, which includes details about the uploaded file. It then runs its code to process or log this information. After finishing, the Lambda function stops running and waits for the next event. This process allows automatic reactions to file uploads without manual intervention.