-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
40 lines (36 loc) · 1.02 KB
/
test.js
File metadata and controls
40 lines (36 loc) · 1.02 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
// https://yrl8ti7pka.execute-api.eu-west-1.amazonaws.com/Prod/test
'use strict';
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = (event, context, callback) => {
console.log('Received event:', JSON.stringify(event, null, 2));
// TODO implement
const done = (err, res) => callback(null, {
statusCode: err ? '400' : '200',
body: err ? err.message : "callback("+ JSON.stringify(res)+")",
headers: {
'Content-Type': 'application/json',
}
});
switch(event.httpMethod) {
case 'GET':
var params = {
TableName: 'MyTestDynamoDBTable',
Limit: 100
};
dynamo.scan(params, done)
break;
case 'PUT':
var params = {
TableName: 'MyTestDynamoDBTable',
Item: {
id: '' + Date.now(),
message: 'Generated number : ' + Math.round(Math.random() * 100)
}
};
dynamo.putItem(params, done);
break;
default:
done(new Error('Unsupported method ' + event.httpMethod));
}
};