Serverless Applications with AWS Lambda
Claudio Canales
Senior DevOps Engineer


Push model
Poll model

Queue (Amazon SQS)
Stream (DynamoDB Streams)

{
"Records": [{
"messageId": "abc-123",
"body": "{\"order_id\": \"A-42\"}"
}]
}
Records.messageId and a body string.body into your own payload.def lambda_handler(event, context):
records = event.get("Records", [])
for record in records:
body = record.get("body", "")
print("BODY:", body)
return {"statusCode": 200}
Records with a default list.body safely.import json
def lambda_handler(event, context):
record = event.get("Records", [])[0]
payload = json.loads(record.get("body", "{}"))
order_id = payload.get("order_id")
print("ORDER_ID:", order_id)
return {"statusCode": 200}
json and read body with a safe default.json.loads to get a dict.ApproximateAgeOfOldestMessage for backlog.




def lambda_handler(event, context):
failures = []
for record in event.get("Records", []):
try:
process(record)
except Exception:
failures.append({"itemIdentifier": record["messageId"]})
return {"batchItemFailures": failures}
messageIds for failed records in batchItemFailures.
Serverless Applications with AWS Lambda