Ravindra BagaleCourses & study guides मराठी

Chapter 93: AWS Lambda and Serverless for DevOps

DevOps

93.10 API and event integrations without real resources

Story (fictional teaching scenario). At a fictional Vadodara store, Yuki from Osaka separates the HTTP adapter from the price calculator. The calculator should not know about HTTP headers.

API and event integrations without real resources
API and event integrations without real resources

Why

The same calculation can serve an API and a queue only if you adapt each event shape deliberately.

What

  • API Gateway accepts HTTP requests and can invoke a Lambda integration.
  • Proxy response has fields such as statusCode and a string body.
  • Adapter converts one event format into your business input and formats the result.
  • S3 notification describes an object event; it does not put the whole object body in the event.
  • Recursion loop occurs when an output triggers the same workflow again, for example writing into the same watched bucket/prefix.

How

  1. Keep the core handler pure.

  2. Parse the chosen integration’s documented event shape.

  3. Return the documented response shape.

  4. Keep input/output event routes separate to avoid loops.

Example 1: Local HTTP-shaped event

  1. Read the input and the code.
from price import api_handler
print(api_handler({'body':'{"qty":3,"unit_paise":4000}'}, None))
  1. Read the result.

Output (tested locally; not on AWS)

{'statusCode': 200, 'body': '{"currency": "INR", "total_paise": 12000}'}
  1. What each part means: body is a JSON string, not already a Python dictionary. The adapter parses it, calls the core, then JSON-encodes the response body. This local test does not prove an actual API Gateway route, authentication or CORS configuration.

Example 2: Prevent a storage-event loop

  1. Read the input and the code.
Read: input/incoming/photo.jpg
Write: output/thumbnails/photo.jpg
Trigger watches only input/incoming/
  1. Read the result.

Output (illustrative; not executed on AWS)

Output object does not match the input trigger.
  1. What each part means: The path plan separates source and destination. A Lambda write that matches its own trigger can invoke the workflow repeatedly and generate charges. No buckets or triggers are created here.

Ravindra Bagale's Tip

Test adapters separately from business logic.

Did you understand? Let us try it once more.