-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmartpill-getPillById.js
More file actions
49 lines (41 loc) · 1.22 KB
/
smartpill-getPillById.js
File metadata and controls
49 lines (41 loc) · 1.22 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
'use strict'
var aws= require('aws-sdk');
const documentClient = new aws.DynamoDB.DocumentClient({region: 'eu-west-1'});
exports.handler = async (event, context, callback) => {
//const pillId = '2f0c8f1c-d969-44cc-b495-740154ac199d';
const pillId = event.pathParameters.id;
console.log('pillId:' + pillId);
console.log(context);
console.log(event)
//console.log('Event: \n'+JSON.stringify(event))
await getPill(pillId).then(data => {
console.log(data.Item);
callback(null, {
statusCode: 200,
body: JSON.stringify(data.Item),
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
})
}).catch((err) => {
console.error(err)
callback({
statusCode: 400,
body: err,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
}, null)
});
};
function getPill(pillId) {
var params = {
TableName: 'smartpill-pills',
Key: {
id: pillId
}
};
return documentClient.get(params).promise();
}