'AWS Amplify 503 error when using Next.js getStaticProps revalidate

I have tried to use Nextjs getStaticProps function on a page

and deployed it on AWS Amplify. However when I gave the option 'revalidate'

AWS cloudfront occurred an error. A 503 error saying it didn't have permission

something like that... does anyone know how to fix this problem?



Solution 1:[1]

First, go in Cloudwatch logs in the region where the error occurred, with Log Insights, find the error. You will get more details about the reason Lambda raised a 503.

I bet it's SQS rights. As quoted here: https://github.com/aws-amplify/amplify-hosting/issues/2175#issuecomment-900514998

Fixable like this:

TL;DR: Add SQS rights to your lambda function execution role.

1/ With your log error, you will get the lambda function name enter image description here

2/ Go to the lambda function configuration, and get Role name, then click to edit enter image description here

3/ Edit the permission policiy in JSON and add this:

       {
            "Action": [
                "sqs:*"
            ],
            "Resource": [
                "arn:aws:sqs:us-east-1:*:*"
            ],
            "Effect": "Allow"
        }

Review and apply, it should work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vincent J