2

My AWS Lambda function integrated with AWS API- Gateway request URL is getting timed out for every first request but it works for the next request.

Note: We also tried to keep the Lambdas warm by scheduling them in CloudWatch, but it didn't work.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • 3
    While Lambda might time out on the first invocation of *your* Lambda function, in general it does not. What is your configured timeout? What programming language are you using? What does your Lambda function actually do when invoked? Does it download large files at startup, for example? – jarmod Oct 20 '17 at 14:03
  • 1
    We need to see your handler in order to help you. Can you include that in your question? – Noel Llevares Oct 20 '17 at 14:04
  • Hi @jarmod my actual problem is with API gateway with Get request when my lambda is integrated to API Gateway and called outside AWS (like iPad Client) the above time-out issue is happening, there is no problem with my Lambda-Function => What is your configured timeout?=For Lambda its 5min but for API gateway its fixed 30sec. =>What programming language are you using? => Python =>My lambda function will call a Google API to bring some information and convert and return it as a JSON. It also calls other Lambda function internally. => Does it download large files at startup = No – Prasen Gupta Oct 21 '17 at 15:48
  • Assuming this is still an issue ... are you saying that the API request through API Gateway makes it to Lambda and the Lambda function times out, or are you saying that the request to API Gateway itself times out? – jarmod Oct 24 '17 at 21:25

2 Answers2

2

It is the problem with the cold start.

You can do few of the following to improve the cold start speed,

If you using node.js,

Webpack:

Pack all the modules that are in separate files into a single file.

If you are using other languages,

Number of Files:

Keep the number of files in less count

LazyLoad:

Don't load everything upfront, lazy load or load modules when needed.

Hope it helps.

Kannaiyan
  • 12,554
  • 3
  • 44
  • 83
1

Without knowing too much about your specific use case, here are two general suggestions:

  1. Increase the memory allocated to your functions, which also increases CPU proportionally. Because your functions are called very infrequently, the added cost of increasing memory size will be balanced by faster cold start times and thus lower billed duration.

  2. Reduce your code size: a smaller .zip, removing unnecessary require()'s in Node.js, etc. For example, if you are including the Async library just to remove a nested callback, consider forgoing that to improve performance.

Refer https://forums.aws.amazon.com/thread.jspa?threadID=181348 for more options.

Srinivas
  • 400
  • 1
  • 8
  • We have done with a first suggestion for increasing the Memory Size, but no luck. I have to check the code once and remove the unnecessary files **Note**: Im having problem with API-Gateway where it is integrated with lambda function and called outside of AWS like IOS client apps – Prasen Gupta Oct 21 '17 at 15:52