1 year ago

#305804

test-img

Saroshi Kir

Where exactly is AWS Websocket API running and how can it utilize lambda functions?

Reading https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html I am confused. Where exactly the WSS is being hosted and where is the processing happening?

In API Gateway you can create a WebSocket API as a stateful frontend for an AWS service (such as Lambda or DynamoDB) or for an HTTP endpoint. The WebSocket API invokes your backend based on the content of the messages it receives from client apps.

So if I use Chalice to deploy my API with websocket support, is it automatically running processing on Lambda? Or do I have to write that manually in boto (ex. invokeFunction) or can I point it to a lambda function?

The maximum lambda function runtime is 15 minutes.

The maximum websocket timeout is 2 hours and 10 minutes of idle.

For example, what happens to the run_some_long_function() that exceeds 15 minutes? If the Lambda function exceeds 15 minutes, does this just disconnect?

from boto3.session import Session
from chalice import Chalice

app = Chalice(app_name='ws-service')
app.experimental_feature_flags.update(['WEBSOCKETS'])
app.websocket_api.session = Session()

app.debug = True


@app.on_ws_connect()
def ws_connect(event):
    app.log.debug(f"New connection established: {event.connection_id}")
    response = run_some_long_process()
    app.websocket_api.send(event.connection_id, response)

I'm also confused as to where the function runs, does it run on Lambda?

Going deeper, looking at the code here on the chalice tutorial, where are the websocket connections being hosted on? Is wss://{id}.execute-api.{region}.amazonaws.com/api/ running on lambda?

python

amazon-web-services

websocket

aws-lambda

chalice

0 Answers

Your Answer

Accepted video resources