-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.js
More file actions
51 lines (42 loc) · 1.41 KB
/
Copy pathread.js
File metadata and controls
51 lines (42 loc) · 1.41 KB
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
let AWS = require("aws-sdk");
let tableName = 'REPLACE'
let accessKeyId = 'REPLACE'
let secretAccessKey= 'REPLACE'
AWS.config.update({
region: 'ap-southeast-1',
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey}
})
let docClient = new AWS.DynamoDB.DocumentClient()
let params = {
TableName: tableName,
// ProjectionExpression: "#n, is_vegetarian, cook_time",
// ExpressionAttributeNames: {
// "#n": "name",
// },
// ExpressionAttributeValues: {
// ":burger": "burger"
// },
// FilterExpression: "#n = :burger",
}
let results = [];
docClient.scan(params, onScan);
function onScan(err, data) {
if (err)
return console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
// update the result array
results = results.concat(data.Items)
console.log("Count: ", data.Count)
console.log("Scanned: ", data.ScannedCount)
// if the scan is complete, the 'LastEvaluatedKey'
// property of the 'data' obj will be undefined
if (!data.LastEvaluatedKey) {
console.log('Scan complete: ', results.length, " items retrieved.")
}
// continue scanning because scan can retrieve a maximum of 1MB of data
if (typeof data.LastEvaluatedKey != "undefined") {
console.log("Scanning for more...");
params.ExclusiveStartKey = data.LastEvaluatedKey;
docClient.scan(params, onScan);
}
}