How do you structure sequential AWS service calls within lambda given all the calls are asynchronous?

后端 未结 8 591
暗喜
暗喜 2021-02-02 14:35

I\'m coming from a java background so a bit of a newbie on Javascript conventions needed for Lambda.

I\'ve got a lambda function which is meant to do several AWS tasks i

8条回答
  •  悲&欢浪女
    2021-02-02 15:14

    A very specific solution that comes to mind is cascading Lambda calls. For example, you could write:

    1. A Lambda function gets something from DynamoDB, then invokes…
    2. …a Lambda function that calls SNS to get an endpoint, then invokes…
    3. …a Lambda function that sends a message through SNS, then invokes…
    4. …a Lambda function that writes to DynamoDB

    All of those functions take the output from the previous function as input. This is of course very fine-grained, and you might decide to group certain calls. Doing it this way avoids callback hell in your JS code at least.

    (As a side note, I'm not sure how well DynamoDB integrates with Lambda. AWS might emit change events for records that can then be processed through Lambda.)

提交回复
热议问题