Skip to content

Instantly share code, notes, and snippets.

@matthew-andrews
Last active June 22, 2016 12:00
Show Gist options
  • Save matthew-andrews/494f0ec8448cb18998a9a9b0fa7875a7 to your computer and use it in GitHub Desktop.
Save matthew-andrews/494f0ec8448cb18998a9a9b0fa7875a7 to your computer and use it in GitHub Desktop.
CloudFormation EventRule bug

Brief description of bug

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.

brokerules

Steps to reproduce

  • 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’

Workaround

  • 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

A better workaround

Add an AWS::Lambda::Permission to the CloudFormation JSON:- https://github.com/Financial-Times/next-url-management-api/pull/126/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment