亚马逊提供local simulator for their Dynamodb product但examples are only in PHP。
这些示例提到传递参数“base_url”以指定您正在使用本地Dynamodb,但是在Node中返回此错误:
{ [UnrecognizedClientException: The security token included in the request is invalid.]
message: 'The security token included in the request is invalid.',
code: 'UnrecognizedClientException',
name: 'UnrecognizedClientException',
statusCode: 400,
retryable: false }
如何让Dynamodb_local在Node中工作?
你应该按照这个blog post设置你的DynamoDB Local,然后你可以简单地使用这个代码:
var AWS= require('aws-sdk'),
dyn= new AWS.DynamoDB({ endpoint: new AWS.Endpoint('http://localhost:8000') });
dyn.listTables(function (err, data)
{
console.log('listTables',err,data);
});
对于Node,请执行以下操作:
const AWS = require('aws-sdk');
const AWSaccessKeyId = 'not-important';
const AWSsecretAccessKey = 'not-important';
const AWSregion = 'local';
const AWSendpoint = 'http://localhost:8000' // This is required
AWS.config.update({
accessKeyId: AWSaccessKeyId,
secretAccessKey: AWSsecretAccessKey,
region: AWSregion,
endpoint: AWSendpoint
});
确保DynamodDB在端口8000上运行。