-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
38 lines (33 loc) · 891 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var AWS = require("aws-sdk");
var fs = require("fs");
const uuidv1 = require("uuid/v1");
AWS.config.update({
region: "us-east-1"
});
var docClient = new AWS.DynamoDB.DocumentClient();
console.log("Importing questions into DynamoDB. Please wait.");
var questions = JSON.parse(fs.readFileSync("questions.json", "utf8"));
questions.forEach(function(question) {
var params = {
TableName: "Questions",
Item: {
ID: uuidv1(),
Category: question.category,
Question: question.question,
Answers: question.answers,
Correct: question.correct
}
};
docClient.put(params, function(err, data) {
if (err) {
console.error(
"Unable to add question",
question.question,
". Error JSON:",
JSON.stringify(err, null, 2)
);
} else {
console.log("PutItem succeeded:", question.question);
}
});
});