2

I'm trying to deploy and test an AWS Lambda function I'm working on and have tried both Zappa and nficano's Python-Lambda.

Zappa using @Task

The problem arises when I trigger an asynchronous function using Zappa's @Task decorator - the task times out in 30s for some reason (that it is called from a Zappa/Flask/Python AWS function invoked via API Gateway may have something to do with it) and using @Task(remote_aws_lambda_function_name='function_name', remote_aws_region='ap-southeast-1') causes the output to freeze and the (unmodified) function to not work at all - I don't even get debug output in zappa tail!

Python-Lambda

While I am able to invoke and test my lambda locally with Python-Lambda, my code doesn't work on deployment, and I miss Zappa's advanced functionality, like 'zappa tail' that allows me to view the logs easily and check my (numerous) debug statements. Currently I have to log into CloudWatch and try to find the log entries (I can't!) and figure out how to fix whatever bug is in the code.

Standalone Zappa

I tried using Zappa to deploy the code directly as a separate Lambda function but I have no clue how to deploy a non-WSGI function using Zappa - as soon as I deploy, I invoke tail to see the function executing without any input and bumming out :P

The logs are as follows:

(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 but both don't solve my problem as I don't seem to be doing something obviously wrong.

How do I get my function to work?

[EDIT/UPDATE]: @kevin-christopher-henry asked if i'd tried using @task_sns as an invocation method, and I have. Unfortunately, I get an error message about Parameter Validation failing similar to the one in the bug report filed on this issue.

(this is from the report - I lost the message when I closed my terminal :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):
    ...
6
  • 1
    Regarding the Zappa solution, it looks like the task has inherited the 30 second API Gateway restriction. Perhaps that's due to the default direct Lambda invocation. Have you tried task_sns? Commented Jan 16, 2018 at 8:57
  • Hi Kevin, yes I have tried @task_sns as well, but I get an error about Parameter validation failing - there is an open bug report out on this as well at github.com/Miserlou/Zappa/issues/1323. Adding the error messafge in an edit to my question as well :) Commented Jan 16, 2018 at 10:32
  • @KevinChristopherHenry is there any way to un-inherit the 30 second API Gateway restriction? Commented Jan 16, 2018 at 10:40
  • 1
    I don't know, I wouldn't have expected that timeout to be there at all. I'd certainly expect the SNS version to avoid it. There is a simple fix to that Zappa bug, so you could apply it yourself and try again. Commented Jan 16, 2018 at 11:06
  • Update : This issue is still not fixed in Zappa as on 08 Feb 17. github.com/Miserlou/Zappa/issues/1323 Commented Feb 8, 2018 at 16:18

1 Answer 1

2

When you are using @task decorator with zappa, the new lambda instance is created with the same configuration of the father (the caller), by default the "timeout_seconds" is 30 in the zappa_settings

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

Take a look at the doc.

So, you probably need to change this value.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried changing this but the function still times out at 30s. Any idea why?
"dev": { "app_function": "application.application", "aws_region": "ap-southeast-1", "profile_name": "default", "project_name": "aws", "runtime": "python3.6", "s3_bucket": "zappa-xxxxxx", "route53_enabled" : "false", "domain" : "masked", "timeout_seconds": 300, "certificate_arn" : "arn:aws:acm:us-east-1:xxxxxxxxxxx:certificate/xxx-xxx-ccc-xxx-xxxxxxx" } }
@kilokahn can you share some of your function?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.