首页 > 解决方案 > Rookie 在 AWS 中找不到 DynamoDB 的连接字符串

问题描述

我不敢相信我不得不问这个问题,但是 AWS 中的连接字符串在哪里,以便我可以连接到我的 DynamoDB?我下面的代码片段显示你想要我需要。查看 AWS 中的“DynamoDB 仪表板”页面,我看不到它。

唯一突出的是 Amazon 资源名称 (ARN) 值,但我认为这不是我下面的代码片段所需的设置(?)

非常感谢,

配置(代码片段)

module.exports = {
  db: 'mongodb://my_user:my_password@url:port/db',
  db_dev: 'mongodb://url:port/db',
};

更新

// Load the SDK and UUID
var AWS = require('aws-sdk');

// Set the region 
AWS.config.update({
  keyId: '...',
  accessKey: '...',
  region: '...'
});

// Create the DynamoDB service object
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
  TableName: 'customer',
  Item: {
    'email' : {S: 'test@test.com'}
  }
};

// Call DynamoDB to add the item to the table
ddb.putItem(params, function(err, data) {

  if (err) {
    console.log(err);
  } 
  else {
    console.log("Success", data);
  }

});

回复

 ResourceNotFoundException: Requested resource not found

 message: 'Requested resource not found',
  code: 'ResourceNotFoundException',
  time: 2019-03-08T21:14:23.831Z,
  requestId: '...',
  statusCode: 400,
  retryable: false,
  retryDelay: ... }

第二次更新

我尝试了以下代码示例,但是当我运行“node myscript.js”时,它超时并出现以下错误

github链接

错误

Error { Error: connect ETIMEDOUT 1.1.1.1:443
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1083:14)
  message: 'connect ETIMEDOUT 1.1.1.1:443',
  errno: 'ETIMEDOUT',
  code: 'NetworkingError',
  syscall: 'connect',
  address: '1.1.1.1',
  port: 443,
  region: 'REGION',
  hostname: 'dynamodb.region.amazonaws.com',

可重试:真,时间:2019-03-08T22:06:46.409Z }

标签: node.jsamazon-dynamodb

解决方案


看起来您正在使用 nodejs SDK?如果是这样,您不使用连接字符串,您可以像这样创建客户端:

// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region 
AWS.config.update({region: 'us-east-1'});

// Create the DynamoDB service object
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});

如果您使用的是本地实例,您还可以执行以下操作:

AWS.config.update({endpoint: 'http://localhost:8000'});

推荐阅读