-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetUser.js
More file actions
51 lines (47 loc) · 1.26 KB
/
Copy pathgetUser.js
File metadata and controls
51 lines (47 loc) · 1.26 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
const AWS = require('aws-sdk');
const region = 'ap-southeast-2';
const documentClient = new AWS.DynamoDB.DocumentClient({ region });
exports.handler = (event, context, callback) => {
if (event.userId) {
const params = {
TableName: 'TodoList',
Key: {
UserId: event.userId
}
}
documentClient.get(params, (err, data) => {
if (err) {
console.log(err);
callback(err);
} else {
callback(null, data);
}
})
} else {
documentClient.scan({ TableName: 'TodoList' }, (err, data) => {
if (err) {
console.log(err);
callback(err);
} else {
callback(null, data);
}
});
}
};
// const getAllUser = () => {
// return new Promise((resolve, reject) => {
// dynamodb.scan({TableName: 'TodoList'}, function(err, data){
// if(err){
// console.log(err);
// reject(err);
// }else{
// const items = data.Items.map(dataField => {
// return {Id: dataField.UserId.S,
// Name: dataField.Name.S,
// Gender: dataField.Gender.S}
// });
// resolve(items);
// }
// });
// });
// };