Home > Blockchain >  List & Remove an EventBridge Lambda trigger using the CLI
List & Remove an EventBridge Lambda trigger using the CLI

Time:12-13

I need to fetch information from a lambda function and remove an existing trigger (EventBridge) from this lambda using CLI (script needs to do that).

Tried to use list-event-source-mappings or delete-event-source-mappings but without success.

Seems like EventBridge isn't supported yet (showing me only SQS,Kinesis,DynamoDB,MQ,MSK) but maybe I am wrong and there is a solution?

CodePudding user response:

You should be able to use events command:

aws events list-rule-names-by-target --target-arn <target_arn>

This will list the names of the rules that are associated with the specified target_arn. You can then use the aws events describe-rule command to get more information about each rule, including the rule id, schedule and pattern.

aws events describe-rule --name <rule_name>

Now to remove a trigger for a Lambda function in EventBridge:

aws events remove-targets --rule <rule_name> --ids <target_id>

The target_id is the unique identifier for the trigger that you want to remove, and the rule_name is the name of the rule that the trigger is associated with.

CodePudding user response:

The APIs you are looking for are in the EventBridge events client:

aws events list-rule-names-by-target <lambda-arn>
aws events list-targets-by-rule --rule <rule-name-from-previous>
aws events remove-targets --rule <rule-name-from-previous> --ids <target-id-from-previous>

Note: The terminology is a bit confusing. An Event Source Mapping is the technical term for the particular polling-type Lambda integration pattern that handles the sources you mention. It is not related to EventBridge events.

  • Related