API Gateway is a fully managed service to create, publish, maintain, monitor and secure APIs. Lambda is a function-as-a-service product. The two can be combined to create serverless, cost-efficient and infinitely scalable APIs. API Gateway can work with a lambda in two ways:
- Lambda Proxy, where the API gateway acts as a simple passthrough and does not mutate the request/response
- Lambda Custom, which allows for request/response transformation based on a mapping template
All requests to API Gateway endpoint are forward straight to the lambda. The return value from lambda function is assumed to be a valid HTTP response and sent back to the client. Lambda has full control over request and response.
Very easy to setup so great for rapid prototyping. However, since everything is hidden in the lambda source code, it is quite difficult to generate documentation off API Gateway configuration.
Offers more control over transmission by having full control over request and response. The request can be modified before it’s handed over to lambda, and the lambda’s return value can be modified before sending it to the client. This is done using mapping templates which are written in Velocity Template Language (VTL).
This integration method completely decouples the API Gateway from Lambda business logic. The mapping templates and other configuration can be easily exported as an Open API specification which makes documentation and SDK generation much easier. Having said that, the templating and configuration requires knowledge of Velocity Template Language (VTL) and JSONPath.