简体   繁体   中英

AWS Gateway takes forever to call the lambda function

I set up some logs to check the incoming requests for an endpoint. I found out Gateway takes at least 10s to call the lambda function:

2016-03-05 21:32:19 UTC+1 Starting execution for request: 5b673e5b-e311-11e5-bf9b-33cf30c5916a
2016-03-05 21:32:19 UTC+1 Method request path: {}
2016-03-05 21:32:19 UTC+1 Method request query string: {}
2016-03-05 21:32:19 UTC+1 Method request headers:
2016-03-05 21:32:19 UTC+1 Method request body before transformations:
2016-03-05 21:32:19 UTC+1 Endpoint request URI:
2016-03-05 21:32:19 UTC+1 Endpoint request headers:
2016-03-05 21:32:19 UTC+1 Endpoint request body after transformations:
### THE CALL IS HERE ###
2016-03-05 21:32:30 UTC+1 Endpoint response body before transformations:
2016-03-05 21:32:30 UTC+1 Endpoint response headers:
2016-03-05 21:32:30 UTC+1 Method response body after transformations:
2016-03-05 21:32:30 UTC+1 Method response headers:
2016-03-05 21:32:30 UTC+1 Successfully completed execution
2016-03-05 21:32:30 UTC+1 Method completed with status: 200

And the logs from the lambda function:

2016-03-05 21:32:29 UTC+1 START RequestId: 5b678c7a-e311-11e5-a92e-7109901c2d08 Version: 65 
2016-03-05 21:32:30 UTC+1 END RequestId: 5b678c7a-e311-11e5-a92e-7109901c2d08 
2016-03-05 21:32:30 UTC+1 REPORT RequestId: 5b678c7a-e311-11e5-a92e-7109901c2d08  Duration: 699.25 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 41 MB

Is that normal? How can I speed this up?

Thanks.

This is not typical, however you might see a small fraction of requests taking much longer than average due to Lambda function initialization, ie "cold start" behavior. You're not billed for the initialization time so you don't see the total time in your Lambda logs.

Best advice to avoid these high worst-case latencies:

  • Ensure your Lambda function has enough memory allocated
  • Ensure your Lambda function is receiving consistent traffic in order to keep the function "warm"

If you follow this advice, and still see consistent latencies in this range over many requests, please let us know.

Cheers, Ryan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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