Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Dynamic route at pages level leds request for public resources to 503 Error #673

Closed
2 tasks done
gparonitti opened this issue Oct 13, 2020 · 11 comments · Fixed by #679 or #681
Closed
2 tasks done

Dynamic route at pages level leds request for public resources to 503 Error #673

gparonitti opened this issue Oct 13, 2020 · 11 comments · Fixed by #679 or #681
Assignees
Labels
bug Something isn't working

Comments

@gparonitti
Copy link

gparonitti commented Oct 13, 2020

Describe the bug

When dynamic route is at pages level (e.g. pages/[lang]/index.jsx) public folder content return a 503 Error: "The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation."

Actual behavior

When getStaticPaths is being used on a root level dynamic route (pages/[lang]/index.jsx), public folder or any not generated request that is issued at that level (www.example.com/foo), respond 503

Expected behavior

Public resources should be served correctly, and all the not generated request at root level should respond with a 404 page

Steps to reproduce

Put a dynamic route at root level /pages/[lang]/index.jsx with getStaticPaths and a public folder with favicon and the favicon is not reachable.

Versions

1.18.0-alpha.5

  • @sls-next/serverless-component version: 1.18.0-alpha.5
  • Next.js version: 9.5.5

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • Please first try using the latest @sls-next/serverless-component release version, which may have already fixed your issue. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.
@dphang
Copy link
Collaborator

dphang commented Oct 13, 2020

May be related to this: #646. I will take a look this week at both. Was making e2e tests more extensible so it's easier to add new ones, we will add tests for these cases so it shouldn't break in the future once fixed.

@dphang dphang added the bug Something isn't working label Oct 13, 2020
@dphang dphang self-assigned this Oct 13, 2020
@gparonitti
Copy link
Author

Yes most likely they are related. I add also this piece of information:

  • if you try to reach https://www.example.com/foo --> 503. Wrong.
  • if you try to reach https://www.example.com/foo/bar --> 404. Correct.

@dphang
Copy link
Collaborator

dphang commented Oct 15, 2020

@gparonitti
Copy link
Author

@dphang I just tried and folder public issue is solved. Unfortunately, the 503 issue which affects the first level of the pathname is not solved. If I request a dynamic route at first level of pages folder which has not been generated with getStaticPaths I receive 503 instead of 404. For example with /pages/[lang]/c where lang could be [en|it|fr]:

@dphang
Copy link
Collaborator

dphang commented Oct 15, 2020

@gparonitti thanks for the update, what does CloudWatch log say for that 503? I don't think I could reproduce it. Are you using fallback: false? I think that is not supported yet, just fallback: true.

@dphang dphang reopened this Oct 15, 2020
@gparonitti
Copy link
Author

There are no log for 503 (I think it is delivered by Cloudfront). Yes the fallback is set to false I'll try true.

@dphang
Copy link
Collaborator

dphang commented Oct 15, 2020

I think adding fallback: false I'll look into how to support it in another PR, should be just pointing S3 URI to the 404.html page

@dphang
Copy link
Collaborator

dphang commented Oct 15, 2020

@gparonitti Hmm, strange, I thought there should still be CloudWatch log, if it mentions Lambda I think it should be in CloudWatch region closest to you

@dphang
Copy link
Collaborator

dphang commented Oct 15, 2020

Anyway, I did repro with fallback: false, it gets a 503 because in Lambda, it is getting access denied from S3:

    "errorType": "AccessDenied",
    "errorMessage": "Access Denied",
    "Code": "AccessDenied",
    "RequestId": "10A4ADA9E37CB239",
    "HostId": "GlBEE7tbZ8Kpxr84Rn5GJV+ikrK0NUOk7hLre7gu8UV3eto4RHRx5Ba+OEGp8iXdZ+NIVmymkyY=",
    "name": "AccessDenied",
    "$fault": "client",
    "$metadata": {
        "httpStatusCode": 403,
        "httpHeaders": {
            "x-amz-request-id": "10A4ADA9E37CB239",
            "x-amz-id-2": "GlBEE7tbZ8Kpxr84Rn5GJV+ikrK0NUOk7hLre7gu8UV3eto4RHRx5Ba+OEGp8iXdZ+NIVmymkyY=",
            "content-type": "application/xml",
            "transfer-encoding": "chunked",
            "date": "Thu, 15 Oct 2020 08:00:15 GMT",
            "server": "AmazonS3"
        },
        "attempts": 1,
        "totalRetryDelay": 0
    },
    "stack": [
        "AccessDenied: Access Denied",
        "    at deserializeAws_restXmlGetObjectCommandError (/var/task/index.js:14734:41)",
        "    at processTicksAndRejections (internal/process/task_queues.js:97:5)"
    ]
}

This is happening because it's trying to retrieve a non-existent page first (getting a 403) and in origin response handler it doesn't have logic to retrieve 404 page, instead it just returns the response as is. We can probably fix to just retrieve the 404.html page in such case in origin request handler.

@dphang
Copy link
Collaborator

dphang commented Oct 15, 2020

Supported 404 pages for fallback: false in 1.18.0-alpha.8. Please try and let me know if there are any issues.

@gparonitti
Copy link
Author

Thank you for the awesome support!!! You're a rockstar 🥇 !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.