检查 Lambda 函数是否可用 boto3

Check if Lambda function is available boto3

我有一个使用 boto3 调用的 lambda 函数。很有可能会有很多并发执行,我知道如果你发出太多请求,Lambda 会限制你。我以同步方式执行此操作,因此没有重试。我想确定我知道什么时候会发生,这样我就可以将请求推送到队列中,稍后再试一次。

如果请求太多,

Boto3 将 return 出错,但我不想为此使用 try and catch。来自 boto3 文档:

For example, Lambda returns TooManyRequestsException if executing the function would cause you to exceed a concurrency limit at either the account level (ConcurrentInvocationLimitExceeded ) or function level (ReservedFunctionConcurrentInvocationLimitExceeded ).

有谁知道有什么方法可以事先检查函数是否可以执行吗?

谢谢。

Does anyone know of a way to check if the function is available for execution before hand?

不,没有办法,除非你自己维护一个计数器,这也是一个粗略的估计。

使用 try catch 语句,因为这是在代码级别使用它的地方,使用异步调用或使用指数退避重试同步调用(增加每次重试之间的持续时间)。