-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
54 lines (49 loc) · 1.35 KB
/
handler.js
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
52
53
54
'use strict';
const AWS = require('aws-sdk');
// offline-ready dynamoDB
const dynamoDB = new AWS.DynamoDB({
region: 'localhost',
endpoint: 'http://localhost:8000'
})
module.exports.hello = (event, context, callback) => {
const params = {
Item: {
"email": {
S: "[email protected]"
},
},
ReturnConsumedCapacity: "TOTAL",
TableName: "usersTable"
};
dynamoDB.putItem(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'insert',
input: data,
}),
};
callback(null, response);
});
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
module.exports.get = (event, context, callback) => {
var params1 = {
TableName: "usersTable"
};
dynamoDB.scan(params1, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'get',
input: data,
}),
};
callback(null, response);
});
};