If you create a CloudWatch Rule/Event through CloudFormation and assign it to a Lambda function, it will get into a slightly broken state where the Lambda function doesn't think it has a CloudWatch Rule/Event attached to it (and won't execute on that schedule) but the Rule/Event will think that it is associated with the Lambda function and won't allow you to add the Rule/Event again.
- Use this reduced test case CloudFormation stack to recreate the bug
- Then go into the CloudWatch Rules/Events section and find the new Rule/Event that you just provisioned (probably called testcase_every-hour)
- Observe that it has a Lambda function as a target (probably called ‘testcase’)
- Then go into the AWS Console in the Lambda section and find the new Lambda function that you just provisioned (probably called ‘testcase’) and click Event sources
- Observe there are no event sources
- Try to add the new Rule/Event that you just provisioned (probably called testcase_every-hour) to the new Lambda function that you just provisioned (probably called ‘testcase’)
- Observe that you cannot and get an error that reads something like: ‘There was an error creating the event source mapping: This function is already attached to the schedule testcase_every-hour’
- Go back to the CloudWatch Rules/Events section and find the new Rule/Event that you just provisioned (probably called testcase_every-hour)
- Click Actions then Edit
- On the right hand side remove the Lambda function as a target by clicking the little x
- Then re-add the Lambda function that you just removed back as a target
- Click Configure details then Update rule
- Then go into the AWS Console in the Lambda section and find the new Lambda function that you just provisioned (probably called ‘testcase’) and click Event sources
- Observe that the hourly Rule/Event is now properly configured as an event source on your Lambda function
Add an AWS::Lambda::Permission
to the CloudFormation JSON:-
https://github.com/Financial-Times/next-url-management-api/pull/126/files