python-3.x - 没有 API 网关的 Zappa Python 3.6 Lambda 函数

标签 python-3.x aws-lambda zappa

我正在尝试部署和测试我正在开发的 AWS Lambda 函数,并且已尝试过 Zappanficano's Python-Lambda

Zappa 使用 @Task

当我使用 Zappa 的 @Task 装饰器触发异步函数时,问题就出现了 - 由于某种原因,任务在 30 秒内超时(它是从通过 API 网关调用的 Zappa/Flask/Python AWS 函数调用的,可能有一些事情要做与它)并使用@Task(remote_aws_lambda_function_name ='function_name',remote_aws_region ='ap-southeast-1')导致输出卡住并且(未修改的)函数根本无法工作 - 我什至没有得到调试输出扎帕尾部!

Python-Lambda

虽然我能够使用 Python-Lambda 在本地调用和测试我的 lambda,但我的代码无法在部署中运行,并且我怀念 Zappa 的高级功能,例如“zappa tail”,它允许我轻松查看日志并检查我的(许多)调试语句。目前,我必须登录 CloudWatch 并尝试查找日志条目(我不能!)并找出如何修复代码中的任何错误。

独立 Zappa

我尝试使用 Zappa 将代码直接部署为单独的 Lambda 函数,但我不知道如何使用 Zappa 部署非 WSGI 函数 - 一旦部署,我就会调用 tail 来查看函数在没有任何输入的情况下执行并感到沮丧:P

日志如下:

(reviv) guha@katana:~/code/virtenvs/aws/connect$ zappa tail --since 1m
Calling tail for stage dev..
[1516065836740] Instancing..
[1516065838128] [DEBUG] 2018-01-16T01:23:58.128Z ebb7aba4-fa5b-11e7-ac3c-0f9b2ef3a86e Zappa Event: {'time': '2018-01-16T01:23:55Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': '985048216164', 'region': 'ap-southeast-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:ap-southeast-1:99487679w65e7r99t:rule/connect-dev-zappa-keep-warm-handler.keep_warm_callback'], 'id': 'dc1fdc11-20d9-bd1a-6234-f040721e38be', 'kwargs': {}}
[1516065838144] [DEBUG] 2018-01-16T01:23:58.128Z ebb7aba4-fa5b-11e7-ac3c-0f9b2ef3a86e Zappa Event: {}
[1516065854137] Instancing..
[1516065855525] [DEBUG] 2018-01-16T01:24:15.525Z f61ef035-fa5b-11e7-8303-85b30872657c Zappa Event: {'resource': '/', 'path': '/', 'httpMethod': 'GET', 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'CloudFront-Forwarded-Proto': 'https', 'CloudFront-Is-Desktop-Viewer': 'true', 'CloudFront-Is-Mobile-Viewer': 'false', 'CloudFront-Is-SmartTV-Viewer': 'false', 'CloudFront-Is-Tablet-Viewer': 'false', 'CloudFront-Viewer-Country': 'IN', 'Host': '7yushhfjij.execute-api.ap-southeast-1.amazonaws.com', 'User-Agent': 'python-requests/2.18.4', 'Via': '1.1 68748abc6b5ec82c2a55779d81161060.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': 'kwDMBT196jKFPNVxn5pbFGArBmuV3p3PqyqAVT2DA8CZYlP33f__fg==', 'X-Amzn-Trace-Id': 'Root=1-5a5d543d-1545839e757e3c8677ffd744', 'X-Forwarded-For': '183.82.183.1, 54.182.245.89', 'X-Forwarded-Port': '443', 'X-Forwarded-Proto': 'https'}, 'queryStringParameters': None, 'pathParameters': None, 'stageVariables': None, 'requestContext': {'requestTime': '16/Jan/2018:01:24:13 +0000', 'path': '/dev', 'accountId': '985048216164', 'protocol': 'HTTP/1.1', 'resourceId': 'kr649sck98', 'stage': 'dev', 'requestTimeEpoch': 1516065853577, 'requestId': 'f6172848-fa5b-11e7-a3bb-e1fb97441a2c', 'identity': {'cognitoIdentityPoolId': None, 'accountId': None, 'cognitoIdentityId': None, 'caller': None, 'sourceIp': '183.82.183.1', 'accessKey': None, 'cognitoAuthenticationType': None, 'cognitoAuthenticationProvider': None, 'userArn': None, 'userAgent': 'python-requests/2.18.4', 'user': None}, 'resourcePath': '/', 'httpMethod': 'GET', 'apiId': '7yushhfjij'}, 'body': None, 'isBase64Encoded': False}
[1516065855548] Entering : reviv_assign_responder
[1516065855548] #################################
[1516065855548] Calling find_closest_responder in 20
[1516065855549] find_closest_responder : 0
[1516065856550] find_closest_responder : 1
[1516065857551] find_closest_responder : 2
[1516065858552] find_closest_responder : 3
[1516065859553] find_closest_responder : 4
[1516065860554] find_closest_responder : 5
[1516065861555] find_closest_responder : 6
[1516065862556] find_closest_responder : 7
[1516065863557] find_closest_responder : 8
[1516065864558] find_closest_responder : 9
[1516065865559] find_closest_responder : 10
[1516065866561] find_closest_responder : 11
[1516065867562] find_closest_responder : 12
[1516065868563] find_closest_responder : 13
[1516065869564] find_closest_responder : 14
[1516065870565] find_closest_responder : 15
[1516065871566] find_closest_responder : 16
[1516065872567] find_closest_responder : 17
[1516065873569] find_closest_responder : 18
[1516065874570] find_closest_responder : 19
[1516065875571] Entering : find_closest_responder
[1516065877568] find_closest_responder : we have a responder!
[1516065877817] Find closest responder called
[1516065877817] Calling wait_one_and_notify in 5
[1516065877817] reviv_assign_responder : 0
[1516065878819] reviv_assign_responder : 1
[1516065879820] reviv_assign_responder : 2
[1516065880821] reviv_assign_responder : 3
[1516065881822] reviv_assign_responder : 4
[1516065882823] Entering : wait_one_and_notify
[1516065883070] incidentid : 09e77bfea119937eee67c2e3d90541ff
[1516065883070] wait_one_and_notify : incident record exists
[1516065883070] wait_one_and_notify : We have a responder : Updating the requester
[1516065883073] [DEBUG] 2018-01-16T01:24:43.73Z f61ef035-fa5b-11e7-8303-85b30872657c Starting new HTTPS connection (1): fcm.googleapis.com
[1516065883479] [DEBUG] 2018-01-16T01:24:43.478Z f61ef035-fa5b-11e7-8303-85b30872657c https://fcm.googleapis.com:443 "POST /fcm/send HTTP/1.1" 200 None
[1516065883484] Success message sent to requester
[1516065883484] wait_one_and_notify : We have a responder : Updating the responder
[1516065883484] [DEBUG] 2018-01-16T01:24:43.482Z f61ef035-fa5b-11e7-8303-85b30872657c Starting new HTTPS connection (1): fcm.googleapis.com
[1516065883853] [DEBUG] 2018-01-16T01:24:43.853Z f61ef035-fa5b-11e7-8303-85b30872657c https://fcm.googleapis.com:443 "POST /fcm/send HTTP/1.1" 200 None
[1516065883854] Notifying those not selected
[1516065883854] Entering : notify_non_selected
[1516065884101] Count of participants : 1
[1516065884101] Count of non-participants : 0
[1516065884101] notify_non_selected : no one to notify
[1516065884101] 'NoneType' object is not iterable
[1516066076720] [DEBUG] 2018-01-16T01:27:56.720Z 7b0e28f0-fa5c-11e7-a1f9-8945479469b0 Zappa Event: {'time': '2018-01-16T01:27:55Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': '985048216164', 'region': 'ap-southeast-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:ap-southeast-1:985048216164:rule/connect-dev-zappa-keep-warm-handler.keep_warm_callback'], 'id': 'd713f870-29a1-5c7b-329c-0fa1aeeb09c1', 'kwargs': {}}
[1516066076721] [DEBUG] 2018-01-16T01:27:56.720Z 7b0e28f0-fa5c-11e7-a1f9-8945479469b0 Zappa Event: {}
^C

This is a similar question , as is this但两者都没有解决我的问题,因为我似乎没有做明显错误的事情。

如何让我的功能发挥作用?

[编辑/更新]:@kevin-christopher-henry 问我是否尝试过使用 @task_sns 作为调用方法,我尝试过。不幸的是,我收到一条有关参数验证失败的错误消息,类似于the bug report filed on this issue中的错误消息。 .

(这是来自报告 - 当我关闭终端时我丢失了消息:P)

 Parameter validation failed:
    Invalid type for parameter Message, value: b'{"task_path": "my_async_task", "capture_response": false, "response_id": null, "args": [{"a": 4, "b": 10}], "kwargs": {}, "command": "zappa.async.route_sns_task"}', type: <class 'bytes'>, valid types: <class 'str'>: ParamValidationError
    Traceback (most recent call last):
    ...

最佳答案

当您在 zappa 中使用 @task 装饰器时,新的 lambda 实例将使用与父级(调用者)相同的配置创建,默认情况下为“timeout_seconds”zappa_settings

中为 30

"timeout_seconds": 30, // Maximum lifespan for the Lambda function (default 30, max 300.)

看看doc .

因此,您可能需要更改此值。

关于python-3.x - 没有 API 网关的 Zappa Python 3.6 Lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48276864/

相关文章:

django - Zappa + RDS 连接问题

python - 关于Python中大数模数的问题

amazon-web-services - AWS Lambda函数访问策略

python-3.x - 使用 Selenium Python 选择 DojoComboBox 的值

python - 如何在 sagemaker 中使用 jsonl 数据进行批量预测?

amazon-web-services - 当一个 lambda 调用另一个 lambda 时,数据传输成本

python - 在 zappa 中调度 lambda 函数来停止实例

django - 对于具有多个图像的 Django 表单,zappa 给出 413 请求实体太大错误

python-3.x - Pandas 列 dType 数组

python - 如何在列表中找到小于 n 的 2 的最高幂?