API Gateway Flashcards
What are some examples/use cases of API Gateway Integrations (at a high level)?
Lambda
- invoke lambda function
- easy way to expost REST API backed by Lambda
HTTP
- expose HTTP endpoints int eh backend
- example: internal HTTP API on premises, Application Load Balancer
- can add rate limiting, caching, user authentications, API keys, etc.
AWS service
- expose any AWS API though the gateway (e.g., posting a message to SQS)
- can add authentication, deploy publicly, rate control, etc.
What are the three endpoint types?
Edge optimized (default)
- For global clients
- Requests are routed through the CloudFront Edge locations (better latency)
- API Gateway still lives in only one region
Regional
- Clients within the same region
- Could manually combine with CloudFront (more control over caching strategies and distribution)
Private
- Can only be accessed from your VPC using an interface VPC endpoint (ENI)
- Use a resource policy to define access
How can you provide user authentication for API Gateway?
- IAM roles (for internal applications)
- Cognito (identity for external users - e.g., mobile users)
- Custom Authorizer (custom logic in a Lambda function)
How can you use Custom Domain Name HTTPS security with API Gateway?
Integration with ACM - AWS certificate manager
- If using Edge-Optimized, then certificate must be in us-east-1
- If using Regional, certificate must be in same region as the API Gateway stage region
- Must set up CNAME or A-alias record in Route 53
How can you deal with API breaking changes from, say, a new version of a Lambda function?
Upversion your API Gateway stage to a be able to handle this new change - this will generate a new API Gateway URL.
What are stage variables, and what is a use case for them?
API Gateway environment variables
- Configure HTTP endpoints your stages talk to (dev, test, prod)
- Pass config params to Lambda through mapping templates
How are stage variables passed to a lambda function?
Through the ‘context’ object in Lambda
- Format: ${stageVariables.variableName}
How can you use stage variables and lambda aliases to manage lambda deployments?
Separate API Gateway into dev, test and prod stages
- Use stage variables to pass in the correct lambda alias to each stage (i.e., prod alias to prod stage)
- Can use the alias in prod to direct a small portion of traffic to the test lambda function (e.g., to test a V2 function)
What is a method to safely test new stage deployments in prod?
Enable canary deployment
- Choose the % of traffic the canary channel receives
- Gives separate metrics and logs for the canary stage
- Can override stage variables for canary
Equivalent of a blue/green deployment for Lambda and API Gateway
What is Integration Type MOCK?
API Gateway returns a response without sending the request to the backend
What is Integration Type HTTP / AWS?
Integration with Lambda & AWS Services
- Must configure both integration request and response
- Setup data mapping using mapping templates for the request and response
What is Integration Type AWS_PROXY?
Lambda proxy
- Request from client is the input to the lambda
- Function is responsible for the logic of request/response
- No mapping template, headers, query string params: these are passed as arguments
What is Integration Type HTTP_PROXY?
- No mapping template
- HTTP request passed to backend, and response from the backend is forwarded by API Gateway
- Possibility to add HTTP Headers (such as an API key, so that it does not need to be passed in via the client)
What is a mapping template, and where can it be used?
Used to modify request / responses
- rename / modify query string params
- modify body content
- add headers
- filter output results
- Content-Type must be set to application/json or application/xml
What is a use-case of mapping templates?
- Transform a REST API request (JSON) to a SOAP API request (XML) for use with a SOAP service
- Rename query string parameter variable names