1
votes

I've configured a CloudWatch rule to run at a given time using cron, but the Lambda is only invoked sometimes. I've ensured that the Lambda execution role has proper permissions, and sometimes the CloudWatch rule will properly run, invoking my Lambda function.

For example, I have programmatically created a rule, enabled it, and added a target using the boto3 client in Python, then when the time came for the role to execute, it does and shows an "invocation error" in the CloudWatch Metrics. I took the same exact rule and changed the cron to be 2 mins later and it worked just fine. I've also tried manually creating the rule in the console with the same sporadic success that I can't figure out how to reproduce.

The only resources I've found online have been to add CloudWatch Events permissions to the Lambda role, but as I said, I've already done that and I'm stuck at where to figure out this issue.

2

2 Answers

1
votes

Solved: I was adding the CloudWatch Events permission to the Lambda function, but not to the proper alias. So I was adding the permission to lambdaFunction, but not to lambdaFunction:DEV, the version that I wanted to invoke. Even though the rest of the rule was set up correctly, I didn't make sure I was using the proper alias with every step of the pipeline setup.

-1
votes

You should investigate the error.

Make sure that the IAM Role used by the Lambda function has permission to write to CloudWatch Logs. The easiest method is to attach the pre-defined policy called AWSLambdaBasicExecutionRole.

Then, whenever the function runs, debug information will be sent to CloudWatch Logs. You can then look in CloudWatch Logs (under the function name) to investigate the cause of the error.