'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?
Solution 1:[1]
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.
Solution 2:[2]
Came across the same issue and found the solution. What you want is remove_permission()
on the lambda client
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mark B |
Solution 2 | tyu46 |
Solution 3 | Yvette Lau |