Lambda Functions
This directory contains Lambda function examples demonstrating various serverless patterns.
Functions
hello-world
A simple "Hello World" function demonstrating basic Lambda concepts.
Key Features:
- Basic event handling
- Logging
- Error handling
- Environment variables
Use Case: Learning Lambda basics
api-handler
An API handler that processes HTTP requests from API Gateway.
Key Features:
- API Gateway integration
- HTTP method routing (GET, POST, PUT, DELETE)
- Request parsing
- CORS support
Use Case: RESTful API backends
event-processor
Processes events from various sources (S3, EventBridge, CloudWatch).
Key Features:
- Multi-source event handling
- S3 event processing
- EventBridge integration
- DynamoDB storage
Use Case: Event-driven processing
Deployment
All functions are deployed via Terraform. See main.tf for configuration.
Testing
Local Testing
bash
# Test hello-world
cd lambda/hello-world
python -c "from lambda_function import lambda_handler; print(lambda_handler({}, None))"AWS Testing
bash
# Invoke function
aws lambda invoke \
--function-name function-name \
--payload '{"key": "value"}' \
response.json
# View response
cat response.jsonBest Practices
- Error Handling: Always wrap code in try/except
- Logging: Use structured logging
- Environment Variables: Use for configuration
- Idempotency: Make functions safely retryable
- Timeouts: Set appropriate timeout values
- Memory: Right-size memory allocation
Monitoring
View logs in CloudWatch:
bash
aws logs tail /aws/lambda/function-name --follow