user7090764
user7090764

Reputation:

Delete trigger on a AWS Lambda function in python

I have a lambda function and for that lambda function my cloudwatch event is a trigger on it...

at the end of the lambda function i need to delete the trigger (cloud watch event ) on that lambda function programatically using python .

how can i do that ? is there any python library to do that?

Upvotes: 3

Views: 3398

Answers (3)

Yvette Lau
Yvette Lau

Reputation: 441

I just finished how to remove the EventBridge events which trigger the lambda function. Below is my code, hope it's helpful

import boto3
    
            eventbridge_client = boto3.client('events')
            lambda_client = boto3.client('lambda')
            remove_target = eventbridge_client.remove_targets(
                Rule=rule_Name,
                EventBusName='default',
                Ids=[
                    target_Name,
                ],
                Force=True
            )
            
            remove_rule = eventbridge_client.delete_rule(
                Name=rule_Name,
                EventBusName='default',
                Force=True
            )
            
            remove_invoke_permission = lambda_client.remove_permission(
                FunctionName="arn:aws:lambda:us-east-1:xxxxxxxxx:function:functionTobeTrgiggerArn",
                StatementId=target_permission_Name,    
            )

Let me know if you still have questions

Upvotes: 0

tyu46
tyu46

Reputation: 71

Came across the same issue and found the solution. What you want is remove_permission() on the lambda client

Upvotes: 1

Mark B
Mark B

Reputation: 200607

The Python library you are looking for is the AWS SDK for Python, also called Boto3. This library is pre-loaded in the AWS Lambda environment. all you have to do is add import boto3 to your Lambda function.

I believe you will need to use the CloudWatchEvents client and either call delete_rule() or remove_targets() depending on exactly what you want to do.

Upvotes: 3

Related Questions