简体   繁体   English

如何使用ruby aws sdk获取活动的lambda工人数?

[英]How to fetch the number of active lambda workers using ruby aws sdk?

So, using AWS Lambda with ruby sdk I can this to call a function: 因此,结合使用AWS Lambda和ruby sdk,我可以调用一个函数:

Aws::Lambda::Client.new.invoke_async params

is there any way to query for the number of currently running lambda instances? 有什么方法可以查询当前正在运行的lambda实例的数量?

Aws::Lambda::Client.new.number_of_running_instances # returns 17

You can use the CloudWatch Metrics API to list AWS Lambda Metrics , including number of concurrent executions (namespace: AWS/Lambda , metric: ConcurrentExecutions ), however there is a caveat. 您可以使用CloudWatch Metrics API列出AWS Lambda指标 ,包括并发执行的次数(命名空间: AWS/Lambda ,指标: ConcurrentExecutions ),但是有一个警告。 As stated in the documentation of the ConcurrentExecutions metric: ConcurrentExecutions指标的文档所述:

Emitted as an aggregate metric for all functions in the account, and for functions that have a custom concurrency limit specified. 作为帐户中所有功能以及指定了自定义并发限制的功能的汇总度量标准而发出。 [...] Measures the sum of concurrent executions for a given function at a given point in time. [...]在给定的时间点测量给定功能的并发执行总和。 Must be viewed as an average metric if aggregated across a time period. 如果跨时间段汇总,则必须将其视为平均指标。

Consequently, you must Manage Concurrency by setting a concurrency limit on your Lambda function before you can view the concurrent execution for a specific function. 因此,必须先通过在Lambda函数上设置并发限制来管理并发 ,然后才能查看特定函数的并发执行。 On the other hand, based on the comments to the question, this may solve the problem you are facing with the choked database. 另一方面,基于对问题的评论,这可以解决您遇到的数据库阻塞问题。 As a side effect, you may have to deal with throttled Lambda invocations instead. 副作用是,您可能不得不处理受限制的Lambda调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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