-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample Lambda fns code.js
81 lines (68 loc) · 1.96 KB
/
sample Lambda fns code.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// test - am lambda functions
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = (event, context, callback) => {
// TODO implement
var payload = {
TableName:"AM_MUSIC"
}
dynamo.scan(payload, function(err,data){
//callback(null,"hello from here");
context.succeed(data);
})
//callback(null, 'Hello from Lambda');
};
//query table - lambda fn
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = (event, context, callback) => {
// TODO implement
var payload = {
ExpressionAttributeValues: {
":a":event.artist
},
TableName:"AM_MUSIC",
KeyConditionExpression: "artist = :a",
};
dynamo.query(payload, function(err,data){
//callback(null,"hello from here");
if(err){
console.log(err);
context.fail(err);
} else {
context.succeed(data);
console.log(data);
}
})
//callback(null, 'Hello from Lambda');
};
// insert - music - Lambda Function
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = (event, context, callback) => {
// TODO implement
//callback(null, 'Hello from Lambda');
console.log(event);
var params = {
Item: {
"artist":event.artist,
"songtitle":event.songtitle,
},
ReturnConsumedCapacity: "TOTAL",
TableName: "AM_MUSIC"
};
dynamo.putItem(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else{ console.log(data);
context.succeed("Inserted Successfully. Artist: " + event.artist + " Song Title: " + event.songtitle);
} // successful response
/*
data = {
ConsumedCapacity: {
CapacityUnits: 1,
TableName: "Music"
}
}
*/
});
};