Question: What service configure để add scaling to Lambda functions?
Answer:
Resources:
MyFunction:
Type: AWS::Lambda::Function
Properties:
ReservedConcurrentExecutions: 100 # Reserved
MyProvisionedConfig:
Type: AWS::Lambda::Alias
Properties:
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: 10 # Provisioned
Problem: Students book appointments với advisors. Lambda + EventBridge process data daily từ DynamoDB, results stored trong S3. Some new appointments trong DynamoDB không được sent to S3.
Root cause: EventBridge chỉ chạy daily, miss real-time changes.
Solution: Add DynamoDB Streams
# Lambda triggered by DynamoDB Stream
def handler(event, context):
for record in event['Records']:
if record['eventName'] == 'INSERT':
new_appointment = record['dynamodb']['NewImage']
# Process and save to S3
save_to_s3(new_appointment)
Problem: Application hosted trong ECS cluster uses RDS database. Performance slows during requests với same read queries.
Solutions:
Add RDS Read Replicas
Add ElastiCache
# ElastiCache pattern
import redis
cache = redis.Redis(host='cache-endpoint')
def get_data(key):
# Try cache first
cached = cache.get(key)
if cached:
return cached
# Cache miss - query database
data = db.query(key)
cache.setex(key, 3600, data) # Cache 1 hour
return data
Problem: Application uses S3 behind CloudFront distribution. New requirements:
Solution: Lambda@Edge + Amazon Cognito
# Lambda@Edge viewer request
def handler(event, context):
request = event['Records'][0]['cf']['request']
headers = request['headers']
# Verify Cognito token
token = headers.get('authorization', [{}])[0].get('value')
if not verify_cognito_token(token):
return {
'status': '401',
'statusDescription': 'Unauthorized'
}
return request
Problem: Build workflow cho school allowing creation of new accounts online.
Architecture:
Student Form → API Gateway → Step Functions
↓
1. Validate Info (Lambda)
↓
2. Check Existing (Lambda + DynamoDB)
↓
3. Create Account (Lambda + DynamoDB)
↓
4. Send Notification (Lambda + SQS/EventBridge)
Services:
Workflow Steps:
Question: How to implement direct service integrations?
Answer: Dive deeper into Serverless Application Lens of AWS Well-Architected Framework.
Examples:
Benefits:
Question: What AWS service process large amounts of data?
Answer: Amazon EMR (Elastic MapReduce)
Use cases:
Exam Tips: