Crownglasses
Crownglasses

Reputation: 21

How to enable/disable cloudwatch event attached to lambda?

I've tried using the Cloudwatch Events/EventBridge JS SDK to enable/disable the rule which does work on the global scale. However, the cloudwatch event that is attached to my lambda does not change in state.

I'm looking to have a lambda that I can enable/disable the CRON aspect of. I see in the AWS UI there is a toggle to enable/disable the cloudwatch event but I'm not able to figure out how to access this functionality with the JS SDK.

toggle of AWS cloudwatch event:

toggle of AWS cloudwatch event

Upvotes: 1

Views: 2605

Answers (2)

Marcin
Marcin

Reputation: 238051

Based on the comments, the problem was that lambda console sometimes shows incorrect associations. The solution was to actually perform a check and test the rules. The test showed that the rule was correctly disabled, even though the console shows otherwise.

Upvotes: 1

Chris Williams
Chris Williams

Reputation: 35146

To disable this you want to look at the event source mapping.

In the JS SDK there is a function named updateEventSourceMapping which is responsible for this.

One of the params you can pass in is Enabled which if set to false will set a disabled flag.

To get the UUID of the event source take a look at the listEventSourceMappings function. You can filter by FunctionName and/or EventSourceArn (in this case the Arn of the CloudWatch Event).

Hope this helps.

Upvotes: 0

Related Questions