简体   繁体   English

如何使用cloudformation模板传递aws-lambda函数名称以生成cloudwatch警报

[英]How to pass aws-lambda function name to generate a cloudwatch alarm using cloudformation template

I have an aws lambda function on top of which I am trying to create a cloudwatch alarm using cloudformation template. 我有一个aws lambda函数,在上面,我想使用cloudformation模板创建一个cloudwatch警报。

Lets say I have a lambda function named MyPackage-MyLambdaFunctionName but when I see my lambda in the aws console, it says MyPackage-MyLambdaFunctionName-M2DEESRWNF6I . 可以说我有一个名为MyPackage-MyLambdaFunctionName的lambda函数,但是当我在aws控制台中看到我的lambda时,它说的是MyPackage-MyLambdaFunctionName-M2DEESRWNF6I

I am able to create the alarm by passing the below in the dimensions: 我可以通过以下尺寸创建警报:

    Dimensions:
      - Name: FunctionName
        Value: MyPackage-MyLambdaFunctionName-M2DEESRWNF6I

(Referring to How to set lambda alarm for specific lambda using CloudFormation ) (请参阅如何使用CloudFormation设置特定lambda的lambda警报

But the issue is the lambda function is having a random component at the end ( -M2DEESRWNF6I ). 但是问题在于lambda函数的末尾有一个随机分量( -M2DEESRWNF6I )。

I have a cloudformation template which goes in a few accounts and creates these lambda functions. 我有一个cloudformation模板,该模板可以使用几个帐户并创建这些lambda函数。 And since these random identifiers are different in each account, I cant put the above in cloudformation template, since it will work for one account but not for the others. 而且,由于每个帐户的随机标识符不同,因此我无法将上述内容放在cloudformation模板中,因为它适用于一个帐户,但不适用于其他帐户。

So, how can I achieve creating these cloudwatch alarms on my lamdba functions using the cloudformation template? 那么,如何使用cloudformation模板在lamdba函数上创建这些cloudwatch警报? such as does " Value " takes regex? 如“ Value ”是否要使用正则表达式? I tried 我试过了

    MyPackage-MyLambdaFunctionName.*  

which didnt work. 这没有用。 Or is there a way to restrict the lambda function name to be just MyPackage-MyLambdaFunctionName (without the random identifier) 还是有一种方法可以将lambda函数名称限制为MyPackage-MyLambdaFunctionName (不带随机标识符)

Any guidance/help is appreciated. 任何指导/帮助表示赞赏。

Thanks 谢谢

The random string on the end of your lambda's function name is there because you're not setting the lambda name explicitly when it's created. lambda函数名称末尾的随机字符串在那里,因为在创建lambda名称时并未明确设置它。 From docs : 文档

FunctionName FunctionName

The name of the Lambda function, up to 64 characters in length. Lambda函数的名称,最多64个字符。 If you don't specify a name, AWS CloudFormation generates one. 如果您未指定名称,则AWS CloudFormation会生成一个名称。

In general, this is correct thing to do because if you do set it, you can't change any of the parameters that require replacement (I can't think of any parameters that require that on lambda though). 通常,这是正确的做法,因为如果您进行设置,就无法更改任何需要替换的参数(尽管如此,我无法想到在lambda上需要该参数的任何参数)。

From the same doc: 从同一文档:

If you specify a name, you cannot perform updates that require replacement of this resource. 如果指定名称,则无法执行需要替换此资源的更新。 You can perform updates that require no or some interruption. 您可以执行不需要或不需中断的更新。 If you must replace the resource, specify a new name. 如果必须替换资源,请指定一个新名称。

To create the alarm you can just reference the Lambda function in the alarm creation code. 要创建警报,您可以仅在警报创建代码中引用Lambda函数。

Like this: 像这样:

Dimensions:
  - Name: "FunctionName"
    Value:
      Ref: LambdaFunctionReference

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

相关问题 来自 cloudwatch 警报 email 的 aws lambda function 的名称 - name of aws lambda function from cloudwatch alarm email 适用于CloudWatch警报的AWS CloudFormation模板:如何通过ElasticSearch节点而不是整个ElasticSearch集群使用指标来描述警报 - AWS CloudFormation template for CloudWatch alarm: how to describe the alarm with metrics by ElasticSearch node, not by whole ElasticSearch cluster 如何为使用 CloudFormation 模板创建的 AWS Lambda function 添加触发器? - How to add triggers for a AWS Lambda function created using a CloudFormation template? 如何触发 AWS Lambda function 错误来测试 Cloudwatch 警报 - How to trigger AWS Lambda function error to test Cloudwatch Alarm 如何使用 CloudFormation 模板更新 AWS Lambda function - How do I update AWS Lambda function using CloudFormation template 给定aws-lambda,如何使用boto3更改与其相关的cloudwatch规则? - Given an aws-lambda, how can I change the cloudwatch rule associated with it using boto3? 使用 cloudformation 基于 lambda 持续时间度量创建 cloudwatch 警报 - Creating cloudwatch alarm based on lambda duration metric using cloudformation 如何将 cloudwatch 警报连接到 lambda 函数 - how to connect a cloudwatch alarm to a lambda function AWS Cloudwatch警报触发lambda - AWS Cloudwatch Alarm to trigger a lambda 针对 Lambda 调用的 AWS CloudWatch 警报 - AWS CloudWatch alarm for Lambda Invocation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM