Serverless Applications with AWS Lambda
Claudio Canales
Senior DevOps Engineer







Records คือ batchbody เป็น stringmessageId ใช้ trace และกรองข้อมูลซ้ำdef lambda_handler(event, context):
records = event.get("Records", [])
for record in records:
body = record.get("body", "")
print("BODY:", body)
return {"statusCode": 200}

import json
def lambda_handler(event, context):
records = event.get("Records") or [{}]
body = records[0].get("body", "{}")
payload = json.loads(body)
oid = payload.get("order_id")
return json.dumps({"order_id": oid})
body เป็น string ให้ parse ด้วย json.loads"{}"order_id แล้ว return JSON ด้วย json.dumps

.get() และค่า default สำหรับ field ที่ไม่จำเป็น
messageId หรือ order_id

Serverless Applications with AWS Lambda