question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Amplify Angular leads to 403 when page refresh

See original GitHub issue

Note: If your question is regarding the AWS Amplify Console service, please log it in the official AWS Amplify Console forum

Which Category is your question related to?

  • Amplify
  • CloudFront
  • Hosting
  • Angular

Amplify CLI Version

4.13.4

What AWS Services are you utilizing?

  • Amplify
  • CloudFront
  • S3

Provide additional details e.g. code snippets

Ay,

I have a strange problem with my Angular app managed by Amplify CLI.

I have added hosting with Amplify CLI and my app is now published from devel and master branches and accessible through CloudFront with custom domains names like staging.dashboard.myapp.com and dashboard.myapp.com.

But I have a problem when a user hit refresh and he’s not on / path OR he got the /mypage by an external link. I got a beautiful error :

Page : https://staging.dashboard.myapp.com/dashboard

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>D9561DA4390E7028</RequestId>
<HostId>
Hy1Gw8M9SaVOCz4DdOJnm/Ln0H7cBQqeVR82AOcNxQKzLhuMkb+QaLqlCpToQQmEAW+MTxMJNoQ=
</HostId>
</Error>

If user use “normal” Angular navigation there is no problem. It’s only when he refresh while being on a page.

If someone got an idea about what’s going on.

Thanks a lot !

EDIT : I have totally removed hosting from my Amplify app and I still got the problem. Did I miss something on Amplify concepts ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:10

github_iconTop GitHub Comments

58reactions
edoardo849commented, May 29, 2020

I have encountered this problem when trying to publish via the Amplify Console. As mentioned in the AWS documentation, from the Amplify Console:

  1. Select your app
  2. Within App Settings, go to Rewrites and redirects
  3. Click on “Open text editor” and copy-paste the following:
[
    {
        "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>",
        "target": "/index.html",
        "status": "200",
        "condition": null
    }
]
2reactions
shide1989commented, May 15, 2020

Had the same issue, it seems that Amplify doesn’t configure the cloudfront template correctly for static websites that uses custom router (like Gatsby Router, or React router)

I changed the template.json, in the couldfront distribution part like this :

                    "DefaultRootObject": "index.html",
                    "CustomErrorResponses": [
                        {
                            "ErrorCachingMinTTL": 300,
                            "ErrorCode": 400,
                            "ResponseCode": 200,
                            "ResponsePagePath": "/index.html"
                        },
                        {
                            "ErrorCachingMinTTL": 300,
                            "ErrorCode": 403,
                            "ResponseCode": 200,
                            "ResponsePagePath": "/index.html"
                        },
                        {
                            "ErrorCachingMinTTL": 300,
                            "ErrorCode": 404,
                            "ResponseCode": 200,
                            "ResponsePagePath": "/index.html"
                        }
                    ]```
Read more comments on GitHub >

github_iconTop Results From Across the Web

403 Access Error returned from Browser possibly caused by ...
The reason why this is happening is because my app was a single paged app. Refreshing causes the browser to request the server,...
Read more >
Troubleshoot the 403 Forbidden error when uploading files ...
The "403 Forbidden" error can occur due to the following reasons: Permissions are missing for s3:PutObject to add an object or s3:PutObjectAcl to...
Read more >
Using redirects - AWS Amplify Hosting
404 redirects occur when a request points to an address that doesn't exist. The destination page of a 404 is displayed instead of...
Read more >
amplify-js
Please see our Amplify JavaScript page within our Documentation site for information around the full ... NON_RETRYABLE_CODES: number[] = [400, 401, 403].
Read more >
How to build an application in minutes with AWS Amplify
With its pre-built UI components in React, Vue, AngularJS, and more, it lets developers tying up the business logic with good-looking applications. Components ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found