Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何与亚马逊合作';节点中的Dynamodb是本地的吗?_Javascript_Node.js_Amazon Web Services_Amazon Dynamodb - Fatal编程技术网

Javascript 如何与亚马逊合作';节点中的Dynamodb是本地的吗?

Javascript 如何与亚马逊合作';节点中的Dynamodb是本地的吗?,javascript,node.js,amazon-web-services,amazon-dynamodb,Javascript,Node.js,Amazon Web Services,Amazon Dynamodb,亚马逊提供了一个新的解决方案,但这是最重要的 这些示例提到传递参数“base_url”以指定您正在使用本地Dynamodb,但在节点中返回此错误: { [UnrecognizedClientException: The security token included in the request is invalid.] message: 'The security token included in the request is invalid.', code: 'Unrecogniz

亚马逊提供了一个新的解决方案,但这是最重要的

这些示例提到传递参数“base_url”以指定您正在使用本地Dynamodb,但在节点中返回此错误:

{ [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在节点中工作?

您应该按照以下步骤设置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);
});

对于节点,请执行以下操作:

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上运行。

我是这样做的,相同的代码在本地或AWS内部工作

只需利用环境变量的存在
DYNAMO\u LOCAL\u ENDPT=”http://localhost:8000“

从“aws sdk”导入{DynamoDB,Endpoint};
const ddb=新的DynamoDB({apiVersion:'2012-08-10'});
if(process.env['DYNAMO\u LOCAL\u ENDPT']){
ddb.endpoint=新端点(process.env['DYNAMO\u LOCAL\u ENDPT']);
}

有一个端到端的例子,用于在Ubuntu上使用带有节点的DynamoDB local,包括设置docker在容器中运行DynamoDB local,以及调用各种DDB操作的示例代码。

您可能也感兴趣,在这种情况下,您可以简单地发出:dyngodb--localThank!看起来PHP SDK使用了“base_url”,而节点SDK使用了“endpoint”。对于像我这样的AWS新手,在第1行之后,我需要添加
AWS.config.update({accessKeyId:“myKeyId”,secretAccessKey:“secretKey”,region:“us-east-1”})我建议您使用环境变量(AWS\u ACCESS\u KEY\u ID、AWS\u SECRET\u ACCESS\u KEY、AWS\u REGION)而不是使用AWS.config.update。我无法使用此代码创建表<代码>dyn.createTable({TableName:'myTbl',AttributeDefinitions:[{AttributeName:'aaa',AttributeType:'S'},],KeySchema:[{AttributeName:'aaa',KeyType:'HASH'}]},function(){dyn.listTables(function(err,data){console.log(data)};})您是否使用aws sdk和此dynamo local创建了表?