我正在尝试部署和测试我正在使用的 AWS Lambda 函数,并尝试了Zappa和nficano 的 Python-Lambda。
Zappa 使用 @Task
当我使用 Zappa 的 @Task 装饰器触发异步函数时出现问题 - 由于某种原因,任务在 30 秒内超时(它是从通过 API Gateway 调用的 Zappa/Flask/Python AWS 函数调用的可能与它有关)并使用 @Task(remote_aws_lambda_function_name='function_name', remote_aws_region='ap-southeast-1') 导致输出冻结并且(未修改的)函数根本不起作用 - 我什至没有在 zappa tail 中获得调试输出!
Python-Lambda
虽然我可以使用 Python-Lambda 在本地调用和测试我的 lambda,但我的代码在部署时不起作用,而且我想念 Zappa 的高级功能,比如让我可以轻松查看日志并检查我的(无数) 调试语句。目前我必须登录 CloudWatch 并尝试查找日志条目(我不能!)并弄清楚如何修复代码中的任何错误。
独立扎帕
我尝试使用 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
这是一个类似的问题,就像这一样,但两者都不能解决我的问题,因为我似乎没有做明显错误的事情。
如何让我的功能正常工作?
[编辑/更新]:@kevin-christopher-henry 问我是否尝试过使用@task_sns 作为调用方法,我有。不幸的是,我收到一条关于参数验证失败的错误消息,类似于在此问题上提交的错误报告中的错误消息。
(这是来自报告 - 我在关闭终端时丢失了消息: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):
...