[英]How to get multiple lambdas in one cloudwatch graph using aws-cdk for python
I am using python in aws-cdk to create some graphs, alerts, sns topics etc.我在 aws-cdk 中使用 python 来创建一些图表、警报、sns 主题等。
My goal is to create a graph that takes a lambda metric for example "Errors" from all lambdas existing in some aws console space我的目标是创建一个图表,该图表采用 lambda 指标,例如来自某些 aws 控制台空间中存在的所有 lambdas 的“错误”
So far I've found examples defining a single lambda from a local path as function, like:到目前为止,我发现从本地路径定义单个 lambda 的示例为 function,例如:
lambdaFunction = _lambda.Function(
self,
id='someLambda',
runtime=_lambda.Runtime.PYTHON_3_8,
'handler='medium.handler',
code=_lambda.Code.from_asset(path='src'),
)
My question is: Is it possible to define all lambdas from aws console to later put them in a graph?我的问题是:是否可以从 aws 控制台定义所有 lambda,以便稍后将它们放入图表中? Is something like this possible?这样的事情可能吗?
errors_widget = aws_cloudwatch.GraphWidget(title= "Errors",
left=[all_lambdas_function.metric_errors()],
width=24)
Yes, you can reference existing AWS resources, such as lambdas defined in the console, in your CDK app.是的,您可以在您的 CDK 应用程序中引用现有的 AWS 资源,例如控制台中定义的 lambda。
First, get a CDK reference to your lambda with the from the from_function_arn
classmethod on Lambda.Function .首先,使用 Lambda.Function 上的from_function_arn
类方法获取对 lambda的 CDK 引用。 You give it the function ARN and it returns an IFunction
type.你给它 function ARN 它返回一个IFunction
类型。
arn = "arn:aws:lambda:eu-west-1:<MYACCOUNT>:function:my-existing-great-function"
my_existing_lambda: IFunction = _lambda.Function.from_function_arn(self, "ExistingLambdaFunction", arn)
From then on, you can call IFunction's methods to add things like metric_errors
on my_existing_lambda
.从那时起,您可以调用IFunction 的方法在 my_existing_lambda 上添加诸如metric_errors
之类的my_existing_lambda
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.