使用Lambda函数执行多个DynamoDb查询

时间:2019-03-17 20:38:44

标签: amazon-web-services aws-lambda amazon-dynamodb aws-sdk

我需要通过dotnet lamba函数对dynamodb进行多个查询(例如,使用分区键和排序键的GetItem和Query)。哪一种是最好的方法?

  1. 在单个lambda中具有后续查询。
  2. 必须为每个查询编写单独的Lambda,并从其他lambda调用它。
  3. 使用步进功能。

1 个答案:

答案 0 :(得分:1)

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.