简体   繁体   中英

Shall we invoke aws lambda functions from our code?

Shall we invoke AWS lambda functions from our code ? This is mainly an AWS good/bad practices question. Is it good to do this or should we create an SNS notification and trigger lambda based on the SNS ?

Some things you might need to consider:

  1. Will the invocation be asynchronous?
  2. What happens if the number of concurrent Lambda already reached the limit , will the invocation be successful?

We've used the SNS approach and has worked without issues. Just an opinion, it is a better option than invoking directly unless there's too much overhead.

If you add another layer of indirection, you still have to deal with the problem of messages arriving faster than you can process them, or bumping up against Lambda limits.

From the Lambda docs:

Asynchronous invocation – If your Lambda function is invoked asynchronously and is throttled, AWS Lambda automatically retries the throttled event for up to six hours, with delays between retries. Asynchronous events are queued before they are used to invoke the Lambda function.

You might have a process that will be intolerant of 6 hour delays - ie. you would rather do a rapid early drop of a message that's being sent too fast to provide backpressure on a process, rather than receive a correct response well after the answer is relevant.

The real question to answer has a lot more to do with your code. If you temporarily run up against resource limits, are you happy with an eventually correct answer, or are you happier with early warning of failure? Triggering events directly from your code exposes you to all of the responsibility of queue management yourself; sending messages to a system that has its own retry and queue logic will force you to learn that system's quirks and management tools when perhaps you are at a point of maximum stress.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM