我有一个“dynamodb_helper.js”,我使用local-dynamo在本地模拟 DynamoDB。我能够在测试之前启动服务器并成功运行它,但是 stopDB() 似乎不起作用。任何帮助/建议将不胜感激。因此,即使在测试结束后,服务器子进程仍会继续运行。
请在下面找到我的代码。
var AWS = require("aws-sdk");
var localDynamo = require('local-dynamo');
var dynamoServer = null;
var dynamodb = null;
var dynamo = null;
module.exports = {
startDB: function() {
dynamoServer = localDynamo.launch({
port: 4567,
detached: true,
heap: '512m',
stdio: 'pipe'
})
var awsConfig = require('../lib/util').ymlParser('aws');
AWS.config.update(awsConfig);
AWS.config.update({
accessKeyId: "TestData",
secretAccessKey: "TestData",
region: "localhost",
endpoint: "http://localhost:4567"
});
dynamodb = new AWS.DynamoDB();
dynamo = dynamodb.DocumentClient;
},
stopDB: function() {
setTimeout(function () {
dynamoServer.kill();
}, 1000)
},
createTable: function() {
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, null, 2));
}
});
}
};