【问题标题】:Error: read ECONNRESET for DynamoDB put request using DocumentClient错误:使用 DocumentClient 读取 DynamoDB put 请求的 ECONNRESET
【发布时间】:2021-09-30 22:33:12
【问题描述】:

我正在尝试使用 DocumentClient 的 put 函数在我的 DynamoDB 表中创建一个新项目,但我收到一个引用 ECONNRESET 的错误。当其他人在堆栈溢出时引用 ECONNRESET 时,这似乎是他们的代理问题。不过,我不确定如何进行调试。

这是我一直在使用的文档:

https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/dynamodb-example-document-client.html https://docs.amplify.aws/guides/functions/dynamodb-from-js-lambda/q/platform/js/

这里是代码

import AWS from 'aws-sdk';
AWS.config.update({region: 'us-east-1'})

const docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});

export const createItem = async (tableName, item) => {
  const params = {
    TableName: tableName,
    Item: item
  };
  console.log(params);
  try {
    await docClient.put(params).promise();
    console.log("Success");
  } catch (err) {
    console.log(err);
  }
}

这是我得到的错误

Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
  errno: -4077
  code: 'TimeoutError',
  syscall: 'read',
  time: 2021-09-25T12:30:23.577z,
  region: 'us-east-1',
  hostname: 'dynamodb.us-east-1.amazonaws.com',
  retryable: true
}

代码和终端截图: https://i.stack.imgur.com/f4JvP.png

【问题讨论】:

  • 您的代码在哪里运行,该主机的网络配置是什么?
  • @peter 我想通了。不过谢谢

标签: node.js amazon-web-services amazon-dynamodb


【解决方案1】:

有人帮了我。我通过代理使用公司 CLI 进行手动本地测试。我必须在 CLI pc login aws --shared-credentials 中使用这个命令,这对我工作的地方来说非常具体。

我还必须包含以下代码:

const proxy = require('proxy-agent');
AWS.config.update({
  httpOptions: {
    agent: proxy(process.env.HTTP_PROXY)
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多