Ich habe eine "dynamodb_helper.js" und ich verwende die local-dynamo, um DynamoDB lokal zu emulieren. Ich bin in der Lage, den Server zu starten und es vor meinem Test erfolgreich auszuführen, aber die stopDB() scheint nicht zu funktionieren. Jede Hilfe/Vorschläge würde sehr geschätzt werden. Der Server Child-Prozess läuft also auch nach dem Ende des Tests weiter.DynamoDBLocal: Wie kann ich DB starten und stoppen?
Hier finden Sie meinen Code unten.
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));
}
});
}
};
frage ich mich nur, ob meine Antwort, das Problem zu lösen geholfen? Wenn ja, darf ich Sie bitten, die Antwort zu akzeptieren? – notionquest
Hallo .... Danke, dass du dir dabei geholfen hast. Ich muss das noch ausprobieren. Wird es überprüfen und bestätigen. –
HI .. die angegebene Lösung funktioniert wie erwartet. - Der Dynamodb-Prozess wird getötet. Nur dass es heißt, "Dynamodb Prozess wurde nicht getötet: undefiniert". Versuchte Drucken "err" und es zeigt undefined. Nicht sicher, warum der Block "else" ausgeführt wird, aber die Lösung funktioniert trotzdem. Vielen Dank! –