Skip to content Skip to sidebar Skip to footer

Is It Possible To Use Group Aggregation In Invoke Lamda Function?

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. lambdas = b

Solution 1:

You have two options here.

  1. Create one lambda that will run all three queries, and aggregate there (example of mongo grouping below).

  2. 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:


Post a Comment for "Is It Possible To Use Group Aggregation In Invoke Lamda Function?"