app.get('/:table_name',function createDatabase(req,res){
AWS.config.update({
region: "",
endpoint: "http://localhost:8000",
accessKeyId :"",
secretAccessKey: ""
});
我知道我可以使用诺言,异步等待,但是我不知道如何在我的代码中使用它们。有人可以帮我吗?我希望它在调用此函数时先创建一个数据库,然后再将其放入数据库中。请帮助!
var dynamodb = new AWS.DynamoDB();
var params11 = {
TableName : "Movies", // TableName : req.params.table_name,
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(params11, function(err, data) {
if (err) {
console.log("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
}
});
console.log("Importing movies into DynamoDB. Please wait.");
var allMovies = JSON.parse(fs.readFileSync('./moviedata.json', 'utf8'));
allMovies.forEach(function(movie) {
param3 = {
TableName: req.params.table_name,
Item: {
"year": movie.year,
"title": movie.title,
"info": movie.info
}
};
docClient.put(param3, function(err, data) {
if (err) {
console.error("Unable to add movie", movie.title, ". Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("PutItem succeeded:", movie.title);
}
});
});
res.send("DONE")
})
app.get('/:table_name',function createDatabase(req,res){AWS.config.update({region:“”,端点:“ http:// localhost:8000”,accessKeyId:“”,secretAccessKey :“”});我知道我可以使用promises,...