sakthi
sakthi

Reputation: 13

Do multiple DynamoDb queries using Lambda function

I need to do multiple queries on dynamodb from my dotnet lamba function (Like GetItem and Query using partition and sort keys). Which one is the best way?

  1. Having subsequent queries in a single lambda.
  2. Have to write separate Lambda for each query and call it from other lambda.
  3. To use the step function.

Upvotes: 1

Views: 1051

Answers (1)

r.pedrosa
r.pedrosa

Reputation: 749

It depend. It is fine to have multiple calls to dynamodb in a single lambda function as long it is doing only one thing. For example, if you have a lambda function serving a restful API resource update and you want to give an HTTP 404 - NotFound, it is fine to call GetItem first and an UpdateItem later on. Same applies you're doing a batch update and "Query using partition and sort keys".

Similarly to methods, usually when you have more than one level of abstraction your function is usually doing too much. Splitting up functions leads to reusability and easier testing. For example, if you want to update a resource and send an email (which require "Query using partition and sort keys"), you definitely don't want to do it in the same lambda function. In this case, using a step function may be a good idea and save you some time but, in the end, should not matter for the discussion if you should have multiple lambda functions or not.

Upvotes: 1

Related Questions