0
votes

I have an aws lambda function on top of which I am trying to create a cloudwatch alarm using cloudformation template.

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.

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)

But the issue is the lambda function is having a random component at the end (-M2DEESRWNF6I).

I have a cloudformation template which goes in a few accounts and creates these lambda functions. 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.

So, how can I achieve creating these cloudwatch alarms on my lamdba functions using the cloudformation template? such as does "Value" takes regex? 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)

Any guidance/help is appreciated.

Thanks

1
If you configure FunctionName for your lambda function, you should get exactly the name you've configured.lexicore
it works now thanks :)starFire

1 Answers

1
votes

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. From docs:

FunctionName

The name of the Lambda function, up to 64 characters in length. If you don't specify a name, AWS CloudFormation generates one.

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).

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.

Like this:

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