How to increase aws amplify request/response timeout?

66 Views Asked by At

I have my NextJS frontend hosted in AWS Amplify. After a few seconds, I keep getting a 504 Gateway Timeout Error. My backend API (hosted elsewhere in ECS) is quite slow, so I want to know what the default AWS Amplify request/response timeout is, and how I can increase it. I am NOT looking for build timeout. This is runtime timeout. The documentation seems lacking in explaining this. Thanks.

1

There are 1 best solutions below

2
Dave On

If you call your back-end directly, like any 3rd party rest API, then you wouldn't be asking about the NextJS/amplify deployment, so I'll assume you're calling your back-end from within /pages/api.

When you do that yourAmplify deploys your /api code as Lambda@Edge. (Note: It may be deployed to a different region. I deploy to Ohio, but the Lambda@Edge is put into N. Virginia.) The Lambda will have a timeout of 30 seconds. You may be able to increase this manually. Lambda@Edge may have a max-timeout of 30 seconds.

Another issues is that the front-end calls the Lambda@Edge function via API Gateway, which has a 29 second timeout that cannot be increased.

If you're getting 504 timeout or similar at about the 30 second mark, it's likely API GW.

How to fix? If your backend is slow, then the front-end API should just "initiate a job" and return quickly, then use a GQL subscription or polling to get the job completion event.