简体   繁体   English

DynamoDB 触发新的 web 套接字连接时的旧 connectionId

[英]Old connectionId when new web socket connection triggered by DynamoDB

I see in CloudWatch that only sporadically the connectionId of new web socket connections are successfully conveyed by an event, triggered by a new and correct DynamoDB entry...我在 CloudWatch 中看到,新的 web 套接字连接的connectionId偶尔会由事件成功传送,由新的正确的 DynamoDB 条目触发...

What I do:我所做的:

  • Connect.连接。 From a localhost front-end, I connect to a web socket wss://xxxxxx.execute-api.us-east-1.amazonaws.com/production .从本地主机前端,我连接到 web 套接字wss://xxxxxx.execute-api.us-east-1.amazonaws.com/production A Connect lambda function stores the connectionId each time successfully in a DynamoDB table. A Connect lambda function 每次成功将connectionId存储在DynamoDB表中。 This connectiondId varies per connection.connectiondId因连接而异。
  • Trigger.扳机。 When a new DynamoDB entry is created, an event is sent by a trigger to a Broadcast lambda function. In its current form this Broadcast function (see below) only prints the connectionId which is conveyed in the event (the result is printed in CloudWatch).创建新的 DynamoDB 条目时,触发器将事件发送到Broadcast lambda function。在当前形式下,此Broadcast function(见下文)仅打印事件中传送的connectionId (结果打印在 CloudWatch 中) . Here is the problem: This connectionId keeps on being the same, while it should change per new connection... Like there is lazy event cache that should be cleared?问题是:这个connectionId一直是一样的,而它应该在每个新连接中改变......就像有惰性事件缓存应该被清除?
  • Disconnect.断开。 When at the front-end the web socket connection is ended, a Disconnect lambda function removes the connectionId successfully from the DynamoDB table.当在前端 web 套接字连接结束时, Disconnect lambda function 从 DynamoDB 表中成功删除了connectionId I thought: This helps to prevent mixing up connectionIds , but not.我想:这有助于防止混淆connectionIds ,但事实并非如此。

Question: How is it possible the same connectionId is repeatedly printed for different web socket connections?问题:如何为不同的 web 套接字connectionId重复打印相同的 connectionId? (see attached images) The DynamoDB tables work as expected, and once triggered should convey the correct table entry/value in the event, isn't it? (见附图)DynamoDB 表按预期工作,一旦触发应该在事件中传达正确的表条目/值,不是吗?

Side question: Why are some log streams in Cloud Watch clustered and others separate?附带问题:为什么 Cloud Watch 中的一些日志流是集群的,而另一些是分开的?

Broadcast lambda python code广播 lambda python 码

import json
import boto3

client = boto3.client('apigatewaymanagementapi', endpoint_url="https://xxxxxx.execute-api.us-east-1.amazonaws.com/production")

def lambda_handler(event, context):
    
    # get connectionId from DynamoDB
    print(event['Records'][0]['dynamodb']['Keys']['connectionid']['S'])

CloudWatch logs for different web socket connections不同 web 套接字连接的 CloudWatch 日志在此处输入图像描述 在此处输入图像描述

This problem was resolved by filtering INSERT events sent to the Broadcast script.此问题已通过过滤发送到Broadcast脚本的 INSERT 事件得到解决。 Since also MODIFY and REMOVE events are sent to the script by DynamoDB, once listed as a trigger, and are therefore logged in CloudWatch.由于 MODIFY 和 REMOVE 事件也由 DynamoDB 发送到脚本,一旦被列为触发器,因此记录在 CloudWatch 中。

Below code does the job in the Broadcast script下面的代码在Broadcast脚本中完成工作

# only look at INSERT dynamodb events and collect connectionId
if record.get('eventName') in ('INSERT'):
    id = record['dynamodb']['Keys']['connectionid']['S']
    print("connectionId: ", id)
else:
    pass

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DynamoDB 在使用 TransactWrtieItems 时返回修改后的文档(旧的或新的) - DynamoDB return the modified document (Old or new) when using TransactWrtieItems 更新 DynamoDB 的 GSI,旧数据不会在新 GSI 中更新 - Update GSI of DynamoDB, old data not update in new GSI Web 套接字连接被禁止(无效的握手响应 getStatus:403) - Web Socket connection forbidden (Invalid handshake response getStatus: 403) Firebase web 使用 onBackgroundMessage() 时会触发两次推送通知 - Firebase web Push notifications is triggered twice when using onBackgroundMessage() 如何在不手动映射的情况下将 Dynamodb stream DynamoDBEvent 新图像或旧图像转换为我自己的具体 object 类型 T? - How to convert Dynamodb stream DynamoDBEvent new image or old image to my own concrete object type T without manual mapping? 在 Airflow Web 服务器上添加新连接时未列出“Google Cloud”连接 - "Google Cloud" connection not listed when adding new connection on Airflow Webserver AWS API 网关 - 有没有办法将 append 元数据发送到连接 session,以便在触发时传播到断开连接? - AWS API Gateway - Is there a way to append metadata to the connection session, so it propagates to disconnect when that is triggered? 如何在 DynamoDB 中为 map 添加新属性? - How to add new attributes to map in DynamoDB? DynamoDB 存储库中何时需要@EnableScan? - When is @EnableScan required in a DynamoDB repository? 事件不是由我的 javascript SignalR Azure 连接触发的 - Events are not triggered by my javascript SignalR Azure connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM