Page 4: Integrating Lambda with Other AWS Services

4. Integrating Lambda with Other AWS Services

The true power of AWS Lambda lies in its tight integration capabilities with other AWS services. This allows you to build powerful and flexible event-driven architectures.

4.1. Amazon S3 Event Integration

Lambda functions can be automatically triggered when objects are created, deleted, or modified in an S3 bucket. This is useful for tasks like image resizing, data processing, or file format conversions.

// Add a trigger to your S3 bucket (via console or CLI/Terraform/CloudFormation)
// Event source: S3 -> Target: Lambda Function

4.2. Amazon DynamoDB Streams Integration

Capture real-time item-level changes (creations, updates, deletions) in a DB table and stream them to a Lambda function. This is used for real-time analytics, data replication, or generating audit logs.

4.3. Amazon API Gateway Integration

API Gateway is used to route HTTP requests to your Lambda functions, allowing you to build custom RESTful API endpoints and host serverless web applications.

// Create a new endpoint in API Gateway and set the integration type to Lambda Function
// Your Lambda function will process the HTTP request and return an HTTP response.
exports.handler = async (event) => {
    // Access event.httpMethod, event.path, event.body, etc.
    return {
        statusCode: 200,
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ message: "Hello from API Gateway & Lambda!" }),
    };
};

4.4. Amazon SNS/SQS Integration

Respond to messages published to an SNS (Simple Notification Service) topic or process messages from an SQS (Simple Queue Service) queue for asynchronous tasks.