skip to Main Content

I have react webapp to make HTTP calls using fetch API.

Calls go to HTTP API gateway which is attached to a lambda function. Lambda fn is nothing but contains my entire node/express app (backend). Please note I have only one big lambda fn with node/express code.

Currently it works fine but problem comes when I hit certain APIs, certain APIs might take more than 30 seconds. In such case, API gateway shows timeout and sends internal server error msg to the client.

Yes, I know there are several options to over come timeout issue.

  1. Use Websocket API gateway. I don’t know if this is right solution as I have to make changes in React (Front-end) code. Basically connect to socket and then wait for response etc. I don’t want to make such changes in the existing implementation.

  2. Use step function: People claim using step fn, 30 seconds timeout issues can be avoided but HOW? I don’t seem to find any right example. Can some pls help to understand this concept how step fn works with API gateway and lambda. Will this even resolve the problem that I face ?

Or pls tell me any other feasible solution if you have.

2

Answers


  1. API Gateway enforces a strict timeout limit of 30 seconds, within which responses must be returned.
    To ensure compliance with this constraint, it is essential to streamline your responses and minimize processing times.

    Well-designed APIs typically deliver responses within milliseconds to a few seconds, as prolonged response times can indicate suboptimal API practices.

    Use step function: People claim using step fn, 30 seconds timeout issues can be avoided but HOW? I don’t seem to find any right example. Can some pls help to understand this concept how step fn works with API gateway and lambda. Will this even resolve the problem that I face ?

    1. For requests requiring extensive processing or longer execution times, consider decoupling the computational tasks.
      Employ an asynchronous processing model where the API immediately returns a success status, while a backend worker or service processes the request separately.

    2. If you have any retrieval operations implement caching mechanisms to expedite data access and diminish response times. Caching frequently requested data can significantly improve performance for GET requests.

    3. If the constraints of API Gateway do not align with your requirements, Consider alternatives like EC2 with a reverse proxy or ELB for flexibility. One such option is to deploy a lightweight EC2 instance configured as a reverse proxy or utilize an Elastic Load Balancer (ELB) to interface with your backend.

    4. Tasks that are too demanding for traditional API models, offload them to a worker-based architecture or leverage AWS Batch and EC2 for more resource-intensive processing.

    Hope this helps.

    Login or Signup to reply.
  2. You can try with Application Load Balance, it can interactive with lambda function and set timeout as you wanted

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search