API Gateway

  • “Front Door” to your APIs

  • Fully Managed, create, publish, maintain, monitor, and secure APIs at any scale

  • HTTP 504 status code :

    • Integration request takes longer than your API Gateway REST API maximum integration timeout parameter

    • Underlying Lambda function has been running for more than 29 seconds causing the API Gateway request to time out

  • HTTP 429:

    • Throttling errors , too many request coming in from users

    • Can be avoided by setting request limit for steady state and burst (max num of concurrent requests)

  • Stage Variable

    • Configure HTTP endpoint for your stages talk to (dev, prod, test)

    • Stage variables are used along with lambda alias

    • Pass configuration parameters (changing values) to a Lambda from API Gateway

    • API Gateway ==== pass parameters ( use stage variable )====> Lambda

    • Ex: You may want to re-use the same Lambda function for multiple stages in your API, but the function should read data from a different Amazon DynamoDB table depending on which stage is being called

  • API Integration

    • You choose an API integration type according to the types of integration endpoint

    • Lambda Function

      • LAMBDA_PROXY (AWS_PROXY)

        • Simple, If your API does not require content encoding or caching,

        • flexible, versatile, and streamlined integration setup

      • LAMBDA_CUSTOM (non-proxy)

        • lambda_proxy + how the incoming request data is mapped to the integration + resulting integration response data is mapped to the method response

    • HTTP (more simpler API Integration)

      • Newer, cheaper, low latency and simple to set up

      • HTTP PROXY

      • HTTP (HTTP Custom)

    • Mock : used for testing/simulations no real backend

    • AWS Service (only non-proxy)

    • VPC Link

  • API Gateway CloudWatch metrics

    • By default, API Gateway metric data is automatically sent to CloudWatch in one-minute periods

    • Latency : measure the overall responsiveness of your API calls

    • IntegrationLatency : measure the responsiveness of the backend

    • CacheHitCount : number of requests served from the API cache in a given period

    • CacheMissCount : number of requests served from the backend in a given period

  • Mapping Templates :

    • Script written in VTL (Velocity Template Language)

    • Convert from json to XML (one form to another)

  • Lambda authorizer :

    • API gateway feature that uses a Lambda function to control access to your API

    • takes the caller's identity as input and returns an IAM policy as output

    • Token-based (TOKEN authorizer ) Lambda authorizer

      • Caller’s identity in a bearer token, such as a JSON Web Token (JWT) or an OAuth token.

    • Request parameter-based (REQUEST authorizer) Lambda authorizer

      • Caller's identity in a combination of headers, query string parameters, stage variables, and $context variables