AWS API网关 - 是否有一种方法可以将元数据附加到连接会话中,因此在触发元时会繁殖以断开连接?
因此,我需要为我的组织构建Websocket API。业务的要求是非常典型的Websocket模式的内容,除了一个细节:
此Websocket API将由我们组织中的不同团队使用,每个团队都需要其自己的单独的ActiveConnections Dynamodb表。
现在典型的Websocket API,将有一个单个连接表连接并断开lambda函数写入/删除。此外,Websocket API中的挂钩确保识别连接/会话所需的连接ID始终在Event.requestContext中。单个连接表的易Peasy。
但是,在我为每个团队拥有单独的主动连接DB/表的方法中,它变得更加复杂。是的,的确,对于连接lambda来说,编码非常容易,因此它可以期望从初始连接请求中的某个地方进行“ teamDatabaseId” - 标题,QueryStringParameters等。
问题是在随后的断开连接中,可以从客户端或服务器。断开连接挂钩将运行断开连接函数,并使用ConnectionID传递默认的请求context,但没有TeamDatabaseID- disconnect lambda需要访问该teamDatabaseID,以了解要从哪个数据库中删除。
有办法这样做吗?是否有一个可以从初始连接中设置值的上下文对象的概念,以便在断开连接时,TeamDatabaseId以某种方式传播到随后的断开lambda?我尝试写信给RequestContext - 这似乎只是为了执行给定的lambda而还活着。
So I need to build a WebSocket API for my org. The requirements from the business are pretty typical websocket pattern stuff except for one detail:
This websocket api will be used by different teams in our org, and each team needs its own separate activeconnections dynamodb table.
Now in a typical websocket api, there would be a single connections table that the connect and disconnect lambda functions write/delete to. Also, the hooks in the websocket api ensure that the connectionId needed to identify a connection/session are always in the event.requestContext. Easy peasy for a single connections table.
However, In my approach of having a separate active connections db/table for each team, it gets more complicated. Yes, it's true that for the connect lambda, It is very easy to code so that it expects a "TeamDatabaseID" from somewhere in the initial connection request - Headers, queryStringParameters, etc.
The problem is in the subsequent disconnect that could be triggered from either client or server. The disconnect hook will run the disconnect function, and pass in the default requestContext with the connectionId, but with no TeamDatabaseID - which the disconnect lambda needs to have access to in order to know which database to delete from.
Is there a way to do this? Is there some notion of a context object that I can set values in from the initial connection, so that when the disconnect happens, the teamDatabaseID is propagated in some way to the subsequent disconnect lambda? I tried writing to the requestContext - and that seems to only be alive for the execution of the given lambda.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以每个团队拥有一个Web套接字API,而不是为多个团队拥有一个Amazon API Gateway Web套接字API吗?
Instead of having a single Amazon API Gateway Web Socket API for multiple teams, could you instead have one Web Socket API per team?