简体   繁体   中英

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?

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM