简体   繁体   English

Amazon Lambda inbound-ses-spam-filter(python)

[英]Amazon Lambda inbound-ses-spam-filter (python)

I want to do some simple filtering with a lambda script that will drop emails based on spamVerdict, virusVerdict, etc. There is a nodejs blueprint that already has most of the functionality I want, but I don't want to use nodejs. 我想使用lambda脚本进行一些简单的过滤,该脚本将基于spamVerdict,virusVerdict等丢弃电子邮件。已经有一个nodejs蓝图,该蓝图已经具有我想要的大多数功能,但是我不想使用nodejs。 Checking the python documentation of the context object seems to indicate that there is no "succeed" method for me to stop processing the SES ruleset. 检查上下文对象的python文档似乎表明我没有停止处理SES规则集的“成功”方法。 Further, simply calling: context.succeed({ "disposition" : "STOP_RULE_SET" }); 此外,只需调用: context.succeed({ "disposition" : "STOP_RULE_SET" }); gives the error: 给出错误:

"errorType": "AttributeError",
"errorMessage": "'LambdaContext' object has no attribute 'succeed'"

I thought Python was a "first class citizen"? 我以为Python是“一流公民”? How do I stop processing the ruleset ? 如何停止处理规则集?

I imagine that the context.succeed() and similar methods were added to the NodeJS version of Lambda due to the asynchronous nature of NodeJS programming. 我想由于NodeJS编程的异步特性,将context.succeed()和类似的方法添加到了Lambda的NodeJS版本中。

For Python Lambda functions it appears you simply need to return 对于Python Lambda函数,您似乎只需要return

Mark B is correct ; 标记B是正确的 ; Python doesn't call back to the context object the way NodeJS does. Python不会像NodeJS那样回调上下文对象。 Rather, it uses the return of the handler function instead. 而是使用处理程序函数的返回。 There's example code in the script I linked below, but for reference, stopping the rule set looks like this: 我在下面链接的脚本中有示例代码,但作为参考,停止规则集如下所示:

    return {'disposition': 'stop_rule_set'}

There's a Python blueprint in the works, but for now I've posted a Pythonized version of the NodeJS blueprint here: 工作中有一个Python蓝图,但现在我在这里发布了NodeJS蓝图的Python化版本:

https://github.com/dldorsey/python-ses/blob/master/lambda_function.py https://github.com/dldorsey/python-ses/blob/master/lambda_function.py

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

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