forked from matthisk/es6console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.js
More file actions
34 lines (29 loc) · 839 Bytes
/
get.js
File metadata and controls
34 lines (29 loc) · 839 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
29
30
31
32
33
34
'use strict';
const dynamo = require('./dynamodb');
module.exports.handler = (event, context, callback) => {
const params = {
TableName: process.env.DYNAMODB_TABLE,
Key: {
id: {
S: event.pathParameters.id,
}
}
};
dynamo.getItem(params, (err, data) => {
if (err) return callback(err);
if (! Object.hasOwnProperty.call(data, 'Item')) {
return callback(null, { statusCode: 404 });
}
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
message: 'Retrieved snippet',
snippet: data.Item.code.S,
}),
};
callback(null, response);
});
};