-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
103 lines (85 loc) · 2.1 KB
/
test.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const { batchWriteAll } = require("./index");
const AWS = require("aws-sdk");
const awsProfile = 'default';
AWS.config.update({region: "us-east-1"});
const credentials = new AWS.SharedIniFileCredentials({profile: awsProfile});
AWS.config.credentials = credentials;
const dynamodb = new AWS.DynamoDB();
const TableName = 'test_db';
const TableName2 = 'test_db2';
// Please Note: This is an E2E test and will creates actual side-effects!
const createTable = () => {
var params = {
TableName ,
KeySchema: [
{ AttributeName: "year", KeyType: "HASH"},
{ AttributeName: "title", KeyType: "RANGE" }
],
AttributeDefinitions: [
{ AttributeName: "year", AttributeType: "N" },
{ AttributeName: "title", AttributeType: "S" }
],
BillingMode: 'PAY_PER_REQUEST'
};
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));
}
});
}
let arr = new Array(26);
arr.fill('')
let items = arr.map( (a, id) => ({
PutRequest: {
Item: {
"title": {
S: `test ${id}`
},
"year": {
N: `${id}`
}
}
}
}))
items2 = [11,12,13,14,15].map( d => ({
PutRequest: {
Item: {
"title": {
S: `test ${d}`
},
"year": {
N: `${d}`
}
}
}
}))
deleteItems = [1,3,5].map( d => ({
DeleteRequest: {
Key: {
"title": {
S: `test ${d}`
},
"year": {
N: `${d}`
}
}
}
}))
var params = {
RequestItems: {
[TableName]: items,
[TableName2]: [...items2, ...deleteItems]
}
};
const callback = (res, ...rest) => {
console.log('>>> >>> >>> ', res, rest)
}
const batchWrite = async () => {
// batchWriteAll(dynamodb, params, callback); // <-- this is with using callback
batchWriteAll(dynamodb, params).promise()// <-- this is with using promise()
.then( res => console.log('results are', res))
.catch( err => console.log('Error are', err))
}
batchWrite();