WebSocket API Gateway Callback Traffic via AWS Private Network

0

Is it possible to send a callback from a pod running on a private EC2 instance to a WebSocket API Gateway via the AWS private network?

Currently, pods call the URL https://{api-id}.execute-api.us-east-1.amazonaws.com/{stage}/@connections/{connection_id}. As I understand it, this traffic passes through the public internet before reaching the WebSocket API Gateway and then forwards to the client. I would like to keep the traffic from pods to the web-socket api gateway (only up to web-socket api gateway and not to the public client) within the AWS private network. Is this possible?

Thank you in advance!

1 Answer
0

A common misconception is that using a public IP address means you are using the internet. Yes, you might be; but there are large networks (such as AWS) that use public IP addressing.

If you are using public IP addresses to communicate between AWS services then the traffic stays on the AWS network. This is called out in the VPC FAQ:

Does traffic go over the internet when two instances communicate using public IP addresses, or when instances communicate with a public AWS service endpoint?

No. When using public IP addresses, all communication between instances and services hosted in AWS use AWS's private network. Packets that originate from the AWS network with a destination on the AWS network stay on the AWS global network, except traffic to or from AWS China Regions.

What's not 100% clear from your question is where (in terms of IP addressing and network location) the client is. It's strongly implied that they are within AWS as well - and in that case (even if the client has a public/Elastic IP address) the traffic stays on the AWS network.

Your question is also about whether a callback can be initiated to an EC2 instance with a private IP address and the answer to that is generally no - you will need some other service (such as a load balancer or even something like Global Accelerator) to provide that "external" to "internal" traffic transfer.

profile pictureAWS
EXPERT
answered 20 days ago
profile pictureAWS
EXPERT
reviewed 20 days ago
  • Hi Brettski,

    Sorry if I was unclear. In my scenario, the client is not within the AWS service and connecting with the websocket api through the public internet. Here's the relevant timestamp in the video: https://youtu.be/4pG07Wgw2cE?feature=shared&t=257

    This is a video from AWS support where exhibit the call back from lamda to websocket api gateay. Is traffic from Lambda to the WebSocket API Gateway (callback to the web-socket api gateway) being routed through the AWS private link?

    If that's the case, what's the purpose of VPC endpoints then? For private API Gateway endpoints, it's possible to attach a VPC endpoint and access those endpoints from private instances within the VPC. I was looking for a similar functionality with WebSocket APIs.

  • "Is the Lambda callback being routed through PrivateLink" - the video is inconclusive. The Lambda function could be using public IP addressing and exist outside a VPC and call the API Gateway service. Or it could be hosted within a VPC and calling the API Gateway private endpoint. Either would work. By WebSocket APIs do you mean HTTP API Gateway? If so, today they do not have a private endpoint.

  • Hi Brettski, I was referring to Websocket API Gateway. https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-overview.html A vpc end-point cannot be attached to a Websocket API. The lamda sends data back to the web-socket API through the callback url. example url. POST https://{api-id}.execute-api.us-east-1.amazonaws.com/{stage}/@connections/{connection_id}. When I checked the vpc flow logs these traffic has a public ip address. I wanted to make sure whether this traffic is routed through the public internet or AWS Network? If it leaves the AWS network, is there a way to keep that traffic within the AWS network.

    https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-data-from-backend.html

  • Given that it is an AWS service: Even though it uses a public IP address the traffic between that and other hosts that are also on AWS stay on the AWS network even if using public IP addresses. I feel that I'm not really answering your question because in order to fully answer the question "does the traffic stay on the AWS network" you need to consider both endpoints (the source and the destination).

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