Table of Contents
- Related Readings
- Key Concepts
- API Gateway and WebSocket
- Route for WebSocket APIs
- Amazon API Gateway concepts
- Choose an API Gateway API integration type
- Set up an API integration request using the API Gateway console
- Set up an integration response in API Gateway
- Use @connections commands in your backend service
- Working with routes for WebSocket APIs
Amazon API Gateway is a service for creating and managing APIs. It can be used as the "front door" of many other AWS services. Here we present one of the classic architecture that uses API Gateway.
As we can see in the diagram above, API Gateway sits between client applications and AWS services, such as AWS Lambda, EC2 and it's actually the entry point of those services. The diagram has three blocks, which corresponds to three-tier architecture. Starting from the left, the first block is the presentation tier. It usually contains UI or web applications. The middle orange block represents the logic tier. This is where business logic sits. The right most block represents data tier.
Combined with AWS Lambda function, API Gateway is a powerful tool to build serverless systems. As a service, it's main responsibility is to create and manage APIs and it is completely decoupled from any business logic and implementation details.
Features of API Gateway
- Support for stateful (WebSocket) and stateless (HTTP ans REST) APIs.
- Powerful, flexible authentication mechanisms such as AWS IAM policies, Lambda authorizer functions and Amazon Cognito user pools
- Amazon API Gateway provides the ability to create MockIntegrations
- Amazon API is granted its own specific Amazon Resource Name that can be referenced in AWS IAM policies.
- API Gateway API Integration Type (more details)
- Integration basically means the connection part between API Gateway and backend services.
- Integration request: The internal interface of a WebSocket API route or REST API method in API Gateway, in which you map the body of a route request or the parameters and body of a method request to the formats required by the backend.
- Integration response: The internal interface of a WebSocket API route or REST API method in API Gateway, in which you map the status codes, headers, and payload that are received from the backend to the response format that is returned to a client app.
- AWS Signature Version 4 (SigV4)
- Connection ID
- Route Selection expressions
API Gateway and WebSocket
Recall that unlike http requests which follows the request-and-response model, WebSocket is a two-way communication and an open connection is maintained between clients and servers. Moreover, the backend on the server side can send callback messages to connected clients.
With API Gateway, we don't necessarily need servers and API Gateway service behaves as if there are servers backing up the APIs.
Route for WebSocket APIs
Copied from AWS website
A WebSocket route in API Gateway is used to direct incoming messages to a specific integration, such as an AWS Lambda function, based on the content of the message. When you define your WebSocket API, you specify a route key and an integration backend. The route key is an attribute in the message body. When the route key is matched in an incoming message, the integration backend is invoked. A default route can also be set for non-matching route keys or to specify a proxy model that passes the message through as-is to backend components that perform the routing and process the request.
----- END -----
©2019 - 2021 all rights reserved