-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (26 loc) · 842 Bytes
/
Copy pathindex.js
File metadata and controls
28 lines (26 loc) · 842 Bytes
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
const AWS = require('aws-sdk'),
dynamoDb = new AWS.DynamoDB.DocumentClient(),
processResponse = require('./process-response'),
TABLE_NAME = 'products';
exports.handler = event => {
if (event.httpMethod === 'OPTIONS') {
return Promise.resolve(processResponse(true));
}
const requestedProductId = event.pathParameters.productId;
if (!requestedProductId) {
return Promise.resolve(processResponse(true, `Error: You missing the productId parameter`, 400));
}
const params = {
TableName: TABLE_NAME,
Key: {
productId: requestedProductId
}
}
return dynamoDb.get(params)
.promise()
.then(response => processResponse(true, response.Item))
.catch(err => {
console.log(err);
return processResponse(true, 'dynamo-error', 500);
});
};