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 回答
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
已回答 7 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则