Connection ID Not getting deleted in dynamo Db table when using websocket API.

0

I have a created a websocket api and the routes to connect and disconnect is set to lambda functions which put connection id to a dynamo db table and delete it respectively. But when the client connection to the websocket is terminated unexpectedly ( device shutdown, wifi/data turn off etc) the client id is not deleted automatically. What can i do to avoid this and make sure if a client is disconnected in any way i have the connection id deleted? Please provide code layout if applicable.

1 Answer
0

Hello Phoenix2819,

I think you are missing step 8 and 9 described in the AWS blog here - Managing sessions of anonymous users in WebSocket API-based applications

The sample code is provided in the blog link above which uses EventBridge to schedule OnDelete function execution every 5 minutes.

Step 8 - If the connection breaks, the WebSocket API calls the OnDisconnect Lambda function automatically. The function marks the connection ID for the given user ID as inactive.

Step 9 - If the user does not return within 5 minutes, Amazon EventBridge scheduler invokes the OnDelete Lambda function, which deletes items with more than 5 minutes of inactivity from Connections and Sessions tables.

AWS
answered 9 months 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