0

What I am trying to do: I want to develop REST APIs on AWS to use in my Android application. The purpose of this REST APIs is to call some other REST APIs, get and process data and send back as response.

What I tried: I followed this AWS tutorial Using AWS Lambda as Mobile Application Backend (Custom Event Source: Android). Everything works as expected but the first time response from AWS is too slow. It is something like ~8 secs. However, next time onwards, in the same session, it is responding in 1 to 2 secs. That may be because it takes a long time in setting up connection and invoking my function at Lambda.

Question: Is there any alternative to this? I want to get the quick response every time, including the first time. Am I trying the right thing (AWS-Lambda) or should I try something else?

user846316
  • 6,037
  • 6
  • 31
  • 40

1 Answers1

2

Increasing the memory size in the lambda configuration. It usually makes it run in a computer with more CPU power, making it slightly faster. However in your case it seems most of the delay is because the function goes "cold" and aws no longer has it in memory.

There are a few things you can try:

-> Reduce the size of your package so it loads faster, the first invocation will still be slow, but you might improve by a few seconds. -> Create another dummy CRON type lambda function that triggers your real lambda every minute or so and makes a dummy request, this should help keep your function in memory. You can learn how to create a lambda cron function (aka lambda scheduled task) here: AWS Lambda Scheduled Tasks

Sergio G
  • 31
  • 3
  • Thanks for the reply but I just want to develop REST APIs which are always available and give response quickly. Lambda is serverless and I don't want that. I am looking for the tutorial which can help me. There are so many public REST APIs available and they are definitiely not using Lambda! They must be using some REST API web application in EC2 or something similar. – user846316 Mar 31 '18 at 18:49