Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway integration with Socket.io

I want to map an API Gateway endpoint with a Socket.io server endpoint, in order to authenticate users through Cognito and, if successful, redirect to the Socket.io server and establish a socket with optional namespace and rooms.

Is that makes sense? I didn't found any example, and API Gateway has only recently enabled a WebSocket API but without support for Socket.io

like image 215
Mauro Losciale Avatar asked Jan 29 '19 18:01

Mauro Losciale


1 Answers

Your question has two parts:

First, the API Gateway using Cognito to authenticate your client;

Second, assuming you are using an EC2 running Node.JS with Socket.IO using API Gateway as an endpoint for your clients.

For the First part, you may use the following reference from AWS documentation. There are several sub-parts when you talk about AWS Cognito, for example including AIM permissions Method Execution to enable API resource endpoint HTTP method.

For the second point, enable API Gateway to establish a synchronous connection with EC2 port running Socket.io you may read some references like this one. You should configure your API Gateway:

  1. Protocol WebSocket connection
  2. Select your Route Selection expression ,e.g. \$default
  3. Map the target backend for each $connect, $disconnect and $default
    1. Use integration type AWS Service
    2. Select EC2 and fill the rest of configs.
like image 180
Rafael Gorski Avatar answered Oct 21 '22 04:10

Rafael Gorski