简体   繁体   English

在 python 中删除 AWS Lambda function 上的触发器

[英]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...我有一个 lambda function 对于那个 lambda function 我的 cloudwatch 事件是它的触发器......

at the end of the lambda function i need to delete the trigger (cloud watch event ) on that lambda function programatically using python.在 lambda function 的末尾,我需要使用 python 以编程方式删除 lambda function 上的触发器(云监视事件)。

how can i do that?我怎样才能做到这一点? is there any python library to do that?有没有 python 图书馆可以做到这一点?

The Python library you are looking for is the AWS SDK for Python , also called Boto3. 您正在寻找的Python库是适用于PythonAWS开发工具包 ,也称为Boto3。 This library is pre-loaded in the AWS Lambda environment. 该库已预加载到AWS Lambda环境中。 all you have to do is add import boto3 to your Lambda function. 您要做的就是将import boto3添加到Lambda函数中。

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. 我相信您将需要使用CloudWatchEvents客户端,并根据您要执行的操作调用delete_rule()remove_targets()

Came across the same issue and found the solution.遇到同样的问题并找到了解决方案。 What you want is remove_permission() on the lambda client你想要的是 lambda 客户端上的remove_permission()

I just finished how to remove the EventBridge events which trigger the lambda function. Below is my code, hope it's helpful我刚刚完成了如何删除触发 lambda function 的 EventBridge 事件。下面是我的代码,希望它有帮助

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如果您还有疑问,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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