I have created three lambda functions 1).postData 2).like 3).comment. I am using invoke lambda function to combine three output. Find the below code for your reference.
You have two options here.
Create one lambda that will run all three queries, and aggregate there (example of mongo grouping below).
Parse your JSON response objects, if they have not been parsed already, and manually aggregate.
Obviously #1 will be more performant, and is way more elegant.
Mongo aggregate/group function example:
db.sales.aggregate(
[
{
$group : {
_id : { month: { $month: "$date" }, day: { $dayOfMonth: "$date" }, year: { $year: "$date" } },
totalPrice: { $sum: { $multiply: [ "$price", "$quantity" ] } },
averageQuantity: { $avg: "$quantity" },
count: { $sum: 1 }
}
}
]
)
If you decide to go the mongo grouping route in your lambda, please keep in mind that it uses in memory storage while it is calculating. If your data set is huge this will give you an error. If you run into that issue set allowDiskUse
to true as the docs suggest.
See: