API Gateway Flashcards

1
Q

What is API Gateway

A

Fully managed service
Allows you to publish, maintain, monitor, and secure your
RESTful APIs.
Serves as the entry point for your back-end services that are powered by :
* AWS Lambda
* Amazon EC2
* Amazon ECS
* AWS Elastic Beanstalk
* or any web application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the sections of the data from to and from the client through API gateway?

A
  • Method Request
  • Integration Request
  • Integration Response
  • Method Response
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the Method Request section do?

A
  • Where client requests are validated
  • Setup authorization type: AWS_IAM, NONE, Lambda Authorizer, Cognito Authorizer
  • Enable usage of API keys
  • Setup Request body validator using a Lambda function
  • You can declare any input body, query string parameters and HTTP headers that your API can accept
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the Integration Request section do?

A

Contains settings about :
* how API Gateway communicates with the backend of your choosing (Lambda function, HTTP endpoint, Mock, AWS Service, VPC Link)
* the Integration type (Proxy or non-proxy) that API Gateway uses
* Mapping templates for non-proxy integration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the Integration Response

A

Only applies to non-proxy integration
Intercepts the result returned from the backend before it’s returned to the client
At least one integration response is required. The default is Passthrough (return as-is)
Transform into another format (base64 or text)
Similar to integration request, you can transfor the response data before it’s returned to the client

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the method response?

A

Where you can define which HTTP headers the method can return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are mapping templates?

A
  • They allow you to MODEL the structure of the request data that gets forwarded to the backend
  • You can also transform backend response data before it’s returned to the client
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the API types that API gateway supports?

A

REST APIs, HTTP APIs, Websocket APIs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are REST APIs?

A
  • The API you use for standard use cases
  • More expensive than HTTP
  • Allows for more control and flexibility
  • Allows you to configure Caching, API keys, usage plans
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are HTTP APIs

A
  • Designed for simple use cases
  • Cheaper than REST APIs
  • Lacks other API Gateway features
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are websocket APIs?

A
  • For real-time applications :
  • Chat applications
  • Trading applications
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between proxy and non-proxy integrations?

A

Proxy

  • requests are transmitted as-is between client and backend, including any headers or query parameters.
  • For responses, your backend is responsible for returning the responses status code, headers and payload to the client.

Non-Proxy
* API Gateway has control over data formatting to and from the backend
* Instead of passing the entire request data, you can use mapping templates to filter at the Integration Request level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are stage variables?

A
  • Key-pairs that your API can access at run time
  • Allow you to perform Canary releases
  • In youre stage you can use stage variables to dynamically point to different endpoints (like lambda aliases)
  • This can be configured in the canary settings of your stage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a canary release?

A
  • Allows you to use the same API Gateway state and route a % of traffic to different endpoints.
  • e.g in the prod stage you can route 10% of traffic to a new lambda alias using stage variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are mapping templates?

A

They can be used to transform requests and responses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In what type of API gateway configuration can you use mapping templates?

A

Non-proxy

17
Q

Give two examples of using mapping templates

A
  • Creating a child resource path and using a mapping template to filter responses to match the resource path
  • Transforming requests/responses to/from legacy protocols like SOAP/XML
18
Q

What is a common problem with API caching?

A

Data is out of sync between the cache and the backend data source

19
Q

How does API Gateway cache data become out of date?

A

Data is not refreshed until the TTL setting on the cache expires

20
Q

What can you do to invalidate the cache?

A
  • Include a Cache-Control header with max-age=0 in the GET request.
  • headers: {‘Cache-Control’: ‘max-age=0’}
21
Q

What is CORS and what is it used for?

A
  • Cross-Origin Resource Sharing
  • A security mechanism that forces browsers to relax the restrictive same-origin policy
22
Q

How does CORS work?

A
  • The backend response needs to include access-control headers to let the browser know that an application authorizes certain sites and methods when the browser makes a preflight OPTIONS request.
  • The Access-Control-Allow-Origin header is a list of allowed domains. The Access-Control-Request-Method header lists the allowed methods (like GET).
23
Q

Where is CORS configured in API Gateway?

A
  • For non-proxy - in the Integration Response section header mappings.
  • For proxy, the backend response must include the headers
24
Q

What types of Authorizors does API Gateway support?

A
  • Cognito User Pool Authorizers
  • Lambda Authorizers
25
Q

What is the difference between cognito authorizers and lambda authorizers?

A
  • Cognito authorizers are used to return a JWT in a customer header from the client
  • Lambda authorizers take a bearer token from an API gateway GET request. API gateway checks if a lambda authorizer has been enabled for the methid and if so calls the lambda function to authorize the request. If successful lambda returns output containing at least one IAM policy and principle identifier.
26
Q

Which is the easiest authorizer to implement?

A

Cognito user pool authorizers. Lambda authorizers require more development than cognito authorizers

27
Q

What are API Gateway Usage Plans?

A
  • Think throttling, access limitations
  • A feature that helps you control different levels of acess to an API.
  • Each usage plan can be used to set distinct throttling and quota limitations based on a subscription which is enforced on specific client API tokens. e.g. Basic, standard, premium plan
28
Q

For troubleshooting API Gateway errors, what can you turn on?

A

Use Cloudwatch access logging and execution logging

29
Q

What is the difference between access logging and execution logging?

A
  • Access logging gives you one entry for each access request.
  • Execution logging is verbose and can cost more, so should be used for troubleshooting specific issues.
    *
30
Q

What sort of metrics does cloudwatch have for API Gateway?

A

The AWS/API GatewayNamespace has the following metrics:
* cache hit/miss counts
* HTTP4.x client side and http5.x server side
* COUNT - total no of API requests
* Integration Latency - Time between API gateway request and backend response (millisecond)
* Latency - end-to-end response (within AWS) from API Gateway request to sending response back to client. This includes the Integration latency and other API gateway overhead (millisecond)

31
Q
A