0
0
AwsConceptBeginner · 3 min read

What is Lambda Trigger: Simple Explanation and Example

A Lambda trigger is an event source that automatically starts an AWS Lambda function when something happens, like a file upload or a database change. It connects AWS services or external events to run your code without you having to manage servers.
⚙️

How It Works

Think of a Lambda trigger like a doorbell. When someone presses the doorbell (an event happens), it rings and alerts you (runs your Lambda function). You don’t have to watch the door all the time; the doorbell does the work of notifying you.

In AWS, triggers are events from services like S3 (file uploads), DynamoDB (database changes), or API Gateway (web requests). When these events occur, AWS automatically runs your Lambda function to handle the task, such as processing data or sending notifications.

This setup lets you build systems that react instantly to changes without running servers 24/7, saving time and money.

đź’»

Example

This example shows a Lambda function triggered by an S3 bucket when a new file is uploaded. The function logs the file name.

python
import json

def lambda_handler(event, context):
    # Get the bucket name and file name from the event
    bucket = event['Records'][0]['s3']['bucket']['name']
    file_name = event['Records'][0]['s3']['object']['key']
    print(f"New file uploaded: {file_name} in bucket: {bucket}")
    return {
        'statusCode': 200,
        'body': json.dumps('File processed successfully')
    }
Output
New file uploaded: example.txt in bucket: my-upload-bucket
🎯

When to Use

Use Lambda triggers when you want your code to run automatically in response to events without managing servers. Common uses include:

  • Processing images or files right after upload to S3
  • Updating search indexes when a database changes
  • Responding to HTTP requests via API Gateway
  • Running scheduled tasks with CloudWatch Events

This helps build scalable, event-driven applications that react quickly and efficiently.

âś…

Key Points

  • A Lambda trigger is an event that starts a Lambda function automatically.
  • Triggers connect AWS services or external events to your code.
  • They enable serverless, event-driven applications.
  • Common triggers include S3 uploads, database changes, and API calls.
âś…

Key Takeaways

A Lambda trigger automatically runs your Lambda function when an event happens.
Triggers connect AWS services like S3, DynamoDB, and API Gateway to Lambda.
They help build efficient, serverless applications that respond instantly.
Use triggers to automate tasks like file processing, database updates, and web requests.