serverless-next.js: The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions.

Describe the bug

In development my login and logout system works. In production it will always throw the error that is the title. Upon investigation with cloudwatch It revealed this subsequent error:

2021-03-16T12:34:42.147Z 4c0268ab-76ba-46e5-8a94-99a2a19586ce ERROR Invoke Error { “errorType”: “TypeError”, “errorMessage”: “Cannot read property ‘0’ of undefined”, “stack”: [ “TypeError: Cannot read property ‘0’ of undefined”, " at isOriginResponse (/var/task/index.js:6236:25)“, " at Runtime.handler$1 [as handler] (/var/task/index.js:5949:9)”, " at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)" ] }

My lambdas have been given full permissions and should have no trouble meeting permission requirements

These errors prevent the page from even loading, as the fetch is requested on page load.

Screenshots/Code/Logs

If applicable, here is my serverless configuration:

myNextApplication: service: evote component: “@sls-next/serverless-component@1.18.0” custom: defaultRegion: us-west-2 defaultEnvironmentGroup: dev provider: name: aws runtime: nodejs12.x stage: dev profile: evote inputs: domain: “evote.space” roleArn: “arn:aws:iam::Theresaproperroleherebutimexcludingitforsecurity” bucketName: “evote-serverless” build: env: USER_TABLE_NAME: Users

Versions

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • Please first try using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (1 by maintainers)

Most upvoted comments

Essentially I’m an idiot, don’t worry about it. 😂

@tejasadvait So here’s what I had to do. So go to your AWS console and create a new IAM role with administrator privileges. Go to your lambda console and perform the following actions to all of your lambdas (there should only be 2-3):

  1. Open your lambda
  2. Go to configuration then permissions
  3. The execution role is at the top, click edit
  4. Assign it your new role
  5. Scroll back to the top of that page and find where it says “Actions”
  6. Under Actions click deploy to Lambda@Edge
  7. At the options at the top click “Use existing CloudFront trigger on this function”
  8. Click deploy then move on to your next one. It may take several minutes for the lambdas to replicate. You’ll have to do this each time you redeploy your software.

As for the get ServerSideProps, here’s one of my examples. In my code I use it to check session data: https://github.com/mcnamara-charles/serverless-evote/blob/master/pages/features.js

Hey @mcnamara-charles,

Thank you again for the detailed response. I tried following your steps and it looks like it is not a permission issue but a Cloudfront caching/Lambda cold-start issue. Your suggestions and example have been quite helpful for my learning. I am going to create a separate issue for my problem. Thank you for all the help.