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
- OS/Environment: Linux Mint
- @sls-next/serverless-component version: @sls-next/serverless-component@1.18.0
Checklist
- You have reviewed the README and FAQs, which answers several common questions.
- Please first try using the most recent
latestoralpha@sls-next/serverless-componentrelease version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the oldserverless-next.jscomponent and theserverless-next.jsplugin are deprecated and no longer maintained.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 16 (1 by maintainers)
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):
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.