API Gateway Flashcards
If I wanted to route traffic based on a weighting in API gateway within a stage - what would I do?
You would set up a canary distribution within your stage and deploy the function you want to test into the canary for that stage
When using IAM for authentication and authorization for API Gateway, how are the credentials passed to API gateway and what format are they in(hint: think of an http request structure)? Why would I use IAM Authentication over other auth types?
Credentials are passed to API gateway using SigV4 in the request header. You would use IAM authentication and authorization when you are working within AWS and using AWS services so you can leverage the full capabilities of IAM - i.e. with lambda, ec2 etc
We have a lambda function backing an API in API Gateway. the integration between API gateway and the lambda function is handled by a lambda proxy. We are also deploying a web front end with javascripts hosted on S3. As such, we will need to enable CORS to allow access from our web domain through to lambda (www.example.com to api.example.com). In this situation how do I enable CORS?
We can’t enable CORS at the API level in this case, as CORS does not work against proxy integration types. What we need to do is edit our lambda function to return the Access-Control-Allow-Origin header (* or domain). This will allow for CORS.
How can an API Gateway cache be invalidated (2 Ways). What do we need to consider in terms of invalidation permissions for one of the methods in particular ?
We can either invalidate the entire cache from the aws console OR we can use the cache-control: max-age=0 header on a request.
If we use the cache-control header we need to ensure that we require authorization to be enabled on the cache because if we don’t ANY client can issue the request and invalidate the cache.
We are monitoring our API gateway deployment and we are seeing some very high values for the IntegrationLatency counter. What does this counter measure. How does it differ from the latency counter?
IntegrationLatency is the time it takes for the API gateway to send a request, and receive the response form the backend. The latency counter represents the time taken from when API gateway receives the request from the client to when it returns the request to the client. This includes the IntegrationLatency AND any overhead from API GW itself. Latency will be higher than integration latency.
I have an API Gateway set up called LambdaAPIGateWayStageProxy. I want to use a stage variable to map a development, production and test lambda alias. How would I specify the name of the Lambda function for the API gateways resource method (assume I am using lambdaAlias to contain the name of the functions alias)?
Lambda APIGateWayStageProxy:${stageVariables.lambdaAlias}
In API gateway, when you deploy a change what is this change deployed to?
Changes are deployed to stages. A stage can have any name you wish.
We have an exisiting legacy application that uses SOAP as its protocol. On analysis, this service can be migrated to lambda for considerable cost savings. The problem we have is that we have a large base of customers who still use the SOAP protocol to interact with our application. Because we are using Lambda, we also intend to expose the service using API gateway. Is there a way that we can maintain the inbound and outbound SOAP protocol to our clients while using Lambda? Which integration type would you need to use on API gateway
We would use API gateway mapping templates to transform the input from legacy services (integration request) to JSON for lambda, and then transform the output from Lambda back to SOAP (integration response). You would need to use the HTTPS/AWS integration type as this allows the use of mapping templates
What deployment strategy would I use if I only needed to service calls to API gateway from one region?
Regional
If I am using Lambda Authorizers inmmy API gateway, where is my authentication data held and what is the sequence of events starting with the client request? What MUST the lambda authorizer return?
- Client requests authentication token from 3rd party
- Request and token are sent to API gateway
- Token and context is sent to lambda authorizer function
- lambda authorizer verifies token with 3rd party
- IAM Principal and Policy is returned and cached
- Request goes to backend for service
If I wanted to allow for cross account access on API gateway, what sort of policy would I use?
Resource Policy
For API gateway, what are the default (secs) , minimum and maximum (hours) TTL’s for the gateway cache?
0 sec (min) 300 secs (5 min) default 1 hr max
Lets say we have an API setup which uses caching, but also has throttling enabled for a usage plan. When a request is made and served from cache is this impacted by the throttle?
The API request will be served from cache ASSUMING that the we are below the throttling limit
I have an API gateway which uses a lambda proxy to instantiate a lambda function via a REST GET method and return some data. I have made a change to my API gateway, but when I try to access it, the changes don’t seem to have been made. Why is this?
Updating and making changes in API gateway do not take effect until those changes are deployed into a stage
We have a lambda function set up with 3 different alias’s - Dev, Test and Prod. Dev points to $latest, test points to version 2 and prod points to version 1. We want to make these accessible through API gateway, but we don’t want to create an entirely new gateway interface for each of the different versions, and we also would like the URI to be static so our testers and developers don;t have to keep changing it if a new version is deployed within lambda. How could we achieve this?
We would ideally set up stages in our API gateway deployment, one stage for dev, test and prod. We would then use stageVariables to map each stage to the specific lambda function which would allow us to have uri’s like:
https://tdyzzpxdya.execute-api.ap-southeast-2.amazonaws.com/Test/udemy
and
https://tdyzzpxdya.execute-api.ap-southeast-2.amazonaws.com/Production/udemy