Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NextJS][ISR] intermittent 503 errors for ISR pages #2175

Open
4 tasks done
andrewgadziksonos opened this issue Aug 17, 2021 · 15 comments
Open
4 tasks done

[NextJS][ISR] intermittent 503 errors for ISR pages #2175

andrewgadziksonos opened this issue Aug 17, 2021 · 15 comments
Labels
bug Something isn't working documentation ssr Server Side Rendering feature

Comments

@andrewgadziksonos
Copy link

Before opening, please confirm:

App Id

dh2ndod2t9wbt

Region

us-east-1

Amplify Console feature

Custom builds, Performance

Describe the bug

  • SSR Lambda is configured with a 10 second timeout which is causing ISR routes to return back an intermittent 503 error based on cold starts, data fetching, etc.

Expected behavior

  • SSR Lambdas should be configured with a 30 second timeout, or allow for a configuration override

Reproduction steps

  1. Create a NextJS app with an ISR route that contains a few data fetching calls, fallback = "blocking"
  2. Deploy to Amplify
  3. Request ISR page that was no pre-rendered during the build
  4. Notice 503

Build Settings

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .next/cache/**/*

Additional information

I have to manually go into the console and change the timeout value from 10 to 30 between every deploy

@quinnturner
Copy link

I had to update the IAM policy of the Lambda manually to include:

        {
            "Effect": "Allow",
            "Resource": "arn:aws:sqs:us-east-1:253925498289:<SQS-ID>.fifo",
            "Action": [
                "sqs:SendMessage"
            ]
        }

Does your Lambda have the correct permissions?

I am in the process of writing a GitHub issue dedicated to this problem.

@andrewgadziksonos
Copy link
Author

I had to update the IAM policy of the Lambda manually to include:

        {
            "Effect": "Allow",
            "Resource": "arn:aws:sqs:us-east-1:253925498289:<SQS-ID>.fifo",
            "Action": [
                "sqs:SendMessage"
            ]
        }

Does your Lambda have the correct permissions?

I am in the process of writing a GitHub issue dedicated to this problem.

Yeah I can confirm that I have the proper IAM policy.

Here's the CloudWatch logs

image

@Athena96
Copy link
Contributor

yes, if you create an app initially not using ISR, then you add an ISR page, then you will need to manually update the IAM policy on the lambda.

@behrooziAWS behrooziAWS added feature-request New feature or request ssr Server Side Rendering feature labels Aug 17, 2021
@swaminator swaminator added documentation and removed feature-request New feature or request labels Aug 26, 2021
@drmzio
Copy link

drmzio commented Aug 27, 2021

Also have the exact same issue. My API route averages 18-20s on local, but when deploying to Amplify, it times-out at 10s.

Heres my StackOverflow post: https://stackoverflow.com/questions/68957437/how-to-increase-timeout-of-amplify-nextjs-ssr-function-from-10s-to-30s

@nicksemansonos
Copy link

We're having a similar issue with a Next.js app. The API routes we configured often can take more than 10 seconds so we'd love to be able to configure the default timeout on the auto-generated Lambdas. It's possible to change it on the Lambda manually, but it will get overwritten next time the project builds.

@swaminator
Copy link
Contributor

@nicksemansonos @drmzio we have updated the default timeout to 30sec. Please let us know if you're still having issues.

@andrewgadziksonos
Copy link
Author

@nicksemansonos @drmzio we have updated the default timeout to 30sec. Please let us know if you're still having issues.

This is amazing @swaminator, thank you!

We've had a redploy in the last 9 hours and I'm still noticing that our lambdas are configured with a 10 sec timeout. Anything special we need to do in order to get the new values?

@konyu
Copy link

konyu commented Oct 1, 2021

@nicksemansonos @drmzio we have updated the default timeout to 30sec. Please let us know if you're still having issues.

I still have this problem in my ISR next.js app. What should I do any change my environment?

Thanks.

@ChrisAtVirtueraDev
Copy link

ChrisAtVirtueraDev commented Oct 1, 2021

Hello! I'm also facing the issue of getting 503 pages. I have a page, where getStaticPaths returns { path: [], fallback: true} and getStaticProps returns {..., revalidate: 900}. First I got the 503 immediately after accessing that page. Which was resolved by increasing the lambda timeouts to 30sec (so i guess the lambda function responsible for the fallback prerendering timed out). But the 503 occurred again on the same page later, when the regeneration was triggered. This time it was the lacking sqs permissions of the lambda functions. I'm not sure though how I am supposed to resolve this issue in a way that persists over redeploys. Am I supposed to completly recreate my amplify project?
Because from the Amplify UI perspective, there is nothing different.

@yogeshydvme
Copy link

In ISR lambda we are still seeing 10 sec as default timeout, whereas other lambda have 30sec. Please help it is blocking us to adopt amplify

@ghost ghost added the bug Something isn't working label Dec 3, 2021
@jnastaskin
Copy link

jnastaskin commented Jan 7, 2022

I had to update the IAM policy of the Lambda manually to include:

        {
            "Effect": "Allow",
            "Resource": "arn:aws:sqs:us-east-1:253925498289:<SQS-ID>.fifo",
            "Action": [
                "sqs:SendMessage"
            ]
        }

Does your Lambda have the correct permissions?

I am in the process of writing a GitHub issue dedicated to this problem.

I'm also having this 503 issue with a deployed page using getStaticPaths/Props..
@quinnturner when you say lambda which lambda are you referring to? After deploying I can see these lambdas with what I assumed was their IAM role name:
image

however, i couldn't find those roles in IAM and so wasn't sure where to update the policy, the closest match was these:

image

do I need to manually create these roles or am i just looking in the wrong place?

@jnastaskin
Copy link

Update: found how to get those role names (had to change the location in lambda console to see the lambdas then get their role names from there), checked the permissions and everything is set but still seeing 503 errors on deployed pages using getStaticPaths/Props

@alacret
Copy link

alacret commented Feb 13, 2022

UPDATE:
This was happening to me on next@12.0.9, After testing many many things, I just downgraded the version to next@12.0.8 and it started working normally.

@ocbrollingpaper
Copy link

UPDATE: This was happening to me on next@12.0.9, After testing many many things, I just downgraded the version to next@12.0.8 and it started working normally.

same happening to latest version, had to downgrade, any update on this?

@ssomlk
Copy link

ssomlk commented Dec 14, 2022

I upgraded from NextJs 11.1.2 to Next 12.3. I cannot see the Image. Gives the 503 error

https://ssomlk-bugfixes3.d31jx5fml0tv9b.amplifyapp.com/_next/image?url=%2F_next%2Fstatic%2Fimage%2Fpublic%2FIIT-2.717a6c886d0cf6b638cf3c0eb928d65f.svg&w=384&q=75

But the weird thing is I am not using next/image but a normal HTML img tag

Tried downgrading to next@12.0.8 but still no luck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation ssr Server Side Rendering feature
Projects
None yet
Development

No branches or pull requests