Skip to content

CloudWatch Alarms is not authorized to perform: lambda:InvokeFunction on the resource because because no resource-based policy allows the lambda:InvokeFunction action

0

Hi,

I'm need to run a fargate task from CloudWatch when a specific alarm is fired. To to that I'm trying to call a lambda function that will run a fargate task. The lambda functiont runs fine in test mode, but when it's called from CloudWatch alarm I see the following error in alarm history:

  • CloudWatch Alarms is not authorized to perform: lambda:InvokeFunction on the resource because because no resource-based policy allows the lambda:InvokeFunction action.*

What I need to do to solve this problem? Thanks!

3 Answers
4

Just adding to what has been mentioned here earlier. First you need to add resource policy to your target lambda function through AWS CLI, catch here is, you can't add resource policy for Cloudwatch Alam through UI unlike other sources such as SNS, SQS etc, so you'll have to add resource policy through AWS CLI as mentioned in AWS Documentation:

aws lambda add-permission \
--function-name my-function-name \
--statement-id AlarmAction \
--action 'lambda:InvokeFunction' \
--principal lambda.alarms.cloudwatch.amazonaws.com \
--source-account 111122223333 \
--source-arn arn:aws:cloudwatch:us-east-1:111122223333:alarm:alarm-name

Once you add this to your target lambda function, CloudWatch Alarm should be able to invoke your lambda function.

Enter image description here

Reference Doc: Using Amazon CloudWatch alarms

AWS
EXPERT

answered 2 years ago

  • "catch here is, you can't add resource policy for Cloudwatch Alam through UI unlike other sources such as SNS, SQS etc, so you'll have to add resource policy through AWS CLI as mentioned in AWS Documentation"

    You can actually add resource -based policy for Lambda via AWS Console.

    1. Go to the lambda function
    2. Go to Configuration tab
    3. In Configuration tab, select Permissions in the left menu
    4. In permissions, go down to Resource-based policy statements
    5. Select the policy and edit
    6. Make sure that AWS Service is seletect
    7. In Service, choose Other
    8. Statement ID is the name for the policy. For exp: AlarmCloudWatchInvoke
    9. In Principal, make sure it is lambda.alarms.cloudwatch.amazonaws.com
    10. In Source ARN, put in the ARN of your alarm
    11. In Action, select lambda:InvokeFunction
    12. Save and test your alarm.
  • i was facing same issue but when i replace principal value cloudwatch.amazonaws.com with principal lambda.alarms.cloudwatch.amazonaws.com it works for me thanks for the sharing such a nice knowledge

2

That error is telling you that the cloudwatch service does not have permission to invoke the lambda. The easiest way is update the resource policy to allow cloudwatch to invoke the service. [1]

If you provide a bit more details on what you are looking to build, we may be able to offer a more detailed answer or recommend patterns that are resilient.

[1] https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions-Lambda : Using Amazon CloudWatch alarms - Lambda alarm actions

AWS

answered 2 years ago

0

Hi, I'm encountering a similar issue despite configuring all permissions correctly. When attempting to trigger an action via a CloudWatch alarm in AWS Lambda, I receive the following error message:

Error: Failed to execute action arn:aws:lambda:[region]:[account_id]:function:[function_name]. Received error: "CloudWatch Alarms is not authorized to perform: lambda:InvokeFunction on the resource because no resource-based policy allows the lambda:InvokeFunction action."

The CloudWatch alarms are being programmatically created and dynamically configured within a Lambda function, specifically to monitor CPU utilization and trigger at <10%. Everything seems to work fine: the alarms are created successfully, and the logic is functioning as expected, with the Lambda function set as the action trigger. However, when the alarm reaches the action state, the error appears in CloudWatch logs, and the Lambda function is not triggered.

I have already ensured that all permissions are set correctly. My Lambda function has a resource-based policy issued through the CLI with the appropriate lambda:InvokeFunction permissions.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Relevant content