Reputation: 41
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.
Upvotes: 2
Views: 2288
Reputation: 400
Without knowing too much about your specific use case, here are two general suggestions:
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.
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.
Upvotes: 1
Reputation: 13035
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.
Upvotes: 2