我在本地设置一个dynamodb来测试我的Node应用程序.为了进行设置,我只需要复制
here中的代码并根据我的需要进行调整.这是代码:
var AWS = require("aws-sdk"); var config = ({ "apiVersion": "2012-08-10","accessKeyId": "abcde","secretAccessKey": "abcde","region": "us-west-2","endpoint": "http://localhost:8001",}); var dynamodb = new AWS.DynamoDB(config); var params = { TableName : "Movies",KeySchema: [ { AttributeName: "year",KeyType: "HASH"},//Partition key { AttributeName: "title",KeyType: "RANGE" } //Sort key ],AttributeDefinitions: [ { AttributeName: "year",AttributeType: "N" },{ AttributeName: "title",AttributeType: "S" } ],ProvisionedThroughput: { ReadCapacityUnits: 10,WriteCapacityUnits: 10 } }; dynamodb.createTable(params,function(err,data) { if (err) { console.error("Unable to create table. Error JSON:",JSON.stringify(err,null,2)); } else { console.log("Created table. Table description JSON:",JSON.stringify(data,2)); } });
这会引发错误但我不明白为什么:
Unable to create table. Error JSON: { "message": "Missing credentials in config","code": "CredentialsError","time": "2017-04-10T11:45:26.748Z","retryable": true,"originalError": { "message": "Could not load credentials from any providers","time": "2017-04-10T11:45:26.747Z","originalError": { "message": "Connection timed out after 1000ms","code": "TimeoutError","retryable": true } } }
感谢任何帮助!
解决方法
更改为以下代码,具有虚拟accessKeyId和secretAccessKey,然后运行它
var AWS = require("aws-sdk"); AWS.config.update({ region: 'us-west-1',accessKeyId: 'accessKeyId',secretAccessKey: 'secretAccessKey',endpoint: new AWS.Endpoint('http://localhost:8000'),}); var dynamodb = new AWS.DynamoDB(); var params = { TableName : "Movies",KeySchema: [ { AttributeName: "year",AttributeDefinitions: [ { AttributeName: "year",ProvisionedThroughput: { ReadCapacityUnits: 10,2)); } });