2.1.1.1. Lambda Triggers and Event Sources
First Principle: Lambda functions are invoked by events from various AWS services and custom applications, enabling event-driven architectures and fostering loose coupling.
AWS Lambda functions are designed to respond to events. An "event source" is an AWS service or a custom application that publishes events, and a "trigger" is the configuration that invokes your Lambda function in response to these events.
Key Lambda Triggers and Event Sources:
- Amazon S3: New object creation, object deletion, etc. (e.g., image resizing, data processing upon upload).
- Amazon DynamoDB Streams: Changes to DynamoDB table items (e.g., real-time analytics, data synchronization).
- Amazon API Gateway: HTTP/S requests (e.g., building RESTful APIs).
- Amazon SQS (Simple Queue Service): Messages arriving in a queue (e.g., asynchronous task processing, microservices communication).
- Amazon SNS (Simple Notification Service): Messages published to a topic (e.g., fan-out notifications, event processing).
- Amazon CloudWatch Events / EventBridge: Schedule-based events (e.g., nightly batch jobs) or AWS service events (e.g., EC2 instance state changes).
- AWS Kinesis Data Streams: Real-time data streams (e.g., clickstream analysis, IoT data ingestion).
Scenario: You're developing a serverless application where new user profiles are uploaded as JSON files to an Amazon S3 bucket. You need a Lambda function to automatically process these files as soon as they are uploaded.
Reflection Question: How does configuring a Lambda trigger from Amazon S3 (an event source) enable an event-driven architecture, fostering loose coupling and automatic processing of uploaded files?