How do I integrate API Gateway (Web Socket) with ALB?

0

Hello! All my application components are placed behind ALB for OIDC integration. I've created API Gateway Web Socket service and want to place it behind the ALB. Is it possible?

3 Answers
0

API Gateway can be placed behind an ALB only for private end points. WebSockets do not support private end points so you can't really do it.

Why do you need to do it? Do you want to do the auth in the ALB? API Gateway can do it as well, either using a Cognito authorizer or using a Lambda authorizer.

profile pictureAWS
EXPERT
Uri
answered a year ago
  • I use multiple ECS services behind ALB. I just needed to add web socket endpoint to them

  • You can add ECS as backend for WebSockets managed by API Gateway. For every request that API gateway receives on one of the connections, it will forward it to the ECS backend, via the ALB, as an HTTP request. Not using a WebSocket, i.e., Client creates a WS to API gateway. Client sends messages on such socket. API Gateway sends the message in an HTTP request to the backend.

0

Hi,

to try to be consistent with your design you could look into this. https://repost.aws/questions/QUV9Q0bXHHRTe3JYnfVPxx3g/is-there-a-way-to-implement-web-sockets-on-aw-ss-elb-elastic-load-balancer

https://aws.amazon.com/blogs/compute/using-websockets-and-load-balancers-part-two/

Also consider looking at https://workshop.serverlesscoffee.com/0-introduction/1-overview.html where IOTCore can be a simpler approach to build websocket compared to API Gateway, as it the later involves many manual setup with Lambda and storage layer to store sessions.

Hope it helps ;)

profile picture
EXPERT
answered a year ago
0

Follow these steps

Create an HTTP API Gateway with WebSocket support: You can create an HTTP API Gateway with WebSocket support using the AWS Management Console or the AWS CLI. After creating the API Gateway, you need to create a route that handles WebSocket traffic.

Create a target group: Create a target group for the WebSocket traffic and register the instances or services that handle the WebSocket traffic.

Create a listener rule: Create a listener rule for the target group to forward traffic from the API Gateway to the registered instances or services. For example, you could create a listener rule that forwards traffic from the API Gateway to the target group based on the path of the WebSocket connection.

Configure the API Gateway: Configure the API Gateway to use the ALB as a target for WebSocket traffic. You can do this by specifying the target group you created in step 2 as the target for WebSocket traffic.

Deploy your WebSocket API: Deploy your WebSocket API and test it by connecting to the WebSocket endpoint.

hash
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions