Search code examples
next.jsamazon-cognitoaws-amplify

RequestHeaderSectionTooLarge: Your request header section exceeds the maximum allowed size


We are using AWS Amplify for our NextJS web app and keep receiving error when ever I try to load the application once deployed to Amplify. Locally there is no issue.

enter image description here

I am using Amplify's default Auth configuration, with basic email and password auth. It looks like it could be related to the Amplify cookie being set in the header but I cannot find any documentation within AWS to prevent this or reduce the amount of information passed with the header. Any help would be appreciated.


Solution

  • I have faced the same issue and was able to solve it. Here's how -

    1. Identify the CloudFront Distribution ID for your app. You can find it in the Deploy logs of your app build console.

    AWS Amplify Build Console

    1. Search & open that particular CF Distribution and go to the Behaviours tab.

    2. Select the Default behaviour (5th one in my case) and hit Edit.

    Cloudfront Distribution Console > Behaviours Tab

    1. Scroll down to the Cache key and origin requests section. Here you will find settings to control what's included in the headers of the request that goes to the server. In my case, I didn't need any Cookies so I chose None, and it solved the issue for me. In your case, you can do the same or pick what all info needs to be in the headers.

    Cloudfront Distribution Console > Behaviours Tab Edit