当通过已建立的ConnectionID在本地调用AWS ApigateWayV2时,为什么ECONNENREFED?
我创建了一个Apigateway流,该流程将当前连接的用户的ConnectionID存储在DynamoDB数据库中。我想通过在本地nodejs文件中使用ApigateWayManagement(@aws-sdk/client-apigatewaymanagementapi )进行测试。
我已经建立了一个连接,并且我的ConnectionID已存储并活跃。我已经写了一个脚本来查看现在是否可以向此连接发送消息:
const { ApiGatewayManagementApi } = require("@aws-sdk/client-apigatewaymanagementapi");
const api = new ApiGatewayManagementApi({ apiVersion: "2018-11-29", endpoint: "wss://REDACTED.execute-api.us-east-1.amazonaws.com/prod" });
const params = {
ConnectionId: "REDACTED",
Data: Buffer.from(JSON.stringify({ Item: { q: "hello world" } }))
};
const run = async () => {
return api.postToConnection(params);
};
run();
但是,我正在收到一个 econnrefused 错误,我不确定我是否在本地遗漏了某些东西来对我的API Gateway进行身份验证。我可以在AWS控制台上完成所有操作,但是使用上述test.js文件本地失败。我的问题是:我可以使用ConnectionID直接与积极建立的连接进行交谈?
I have created a flow of ApiGateway that stores connectionId of all currently connected users in a DynamoDB database. I want to test by using ApiGatewayManagement ( @aws-sdk/client-apigatewaymanagementapi ) locally with PostToConnection in a local NodeJS file.
I have established a connection, and my connectionId has been stored and is active. I have written a script to see if I can now send a message to this connection:
const { ApiGatewayManagementApi } = require("@aws-sdk/client-apigatewaymanagementapi");
const api = new ApiGatewayManagementApi({ apiVersion: "2018-11-29", endpoint: "wss://REDACTED.execute-api.us-east-1.amazonaws.com/prod" });
const params = {
ConnectionId: "REDACTED",
Data: Buffer.from(JSON.stringify({ Item: { q: "hello world" } }))
};
const run = async () => {
return api.postToConnection(params);
};
run();
However, I am receiving an ECONNREFUSED error and I am unsure if I am leaving something out locally to authenticate to my API Gateway. I am able to do this all on AWS console, but using above test.js file locally fails. My question is: Can I use connectionId to talk directly to this connection that is actively established?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道,看起来很奇怪,但是请尝试将端点从“ WSS:” 转换为“ https:” 。
迁移到V3 SDK后,我遇到了同样的问题。
我使用自定义域名,如果以前必须指定
,则仅在指定后才开始工作
I know, it looks strange, but please try to change endpoint from "wss:" to "https:".
I got the same problem after migration to v3 SDK.
I use custom domain name and if previously I had to specify
Now it started to work only after I specified