aws-amplify / aws-amplify/amplify-hosting

Access denied error in all routes Nextjs v12.2.5 SSG deployment

Open
#3,040 4 comments 0 reactions 0 assignees View on GitHub
bug ssr
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.

### App Id

NEW_APP

### AWS Region

us-west-2

### Amplify Hosting feature

Deployments, Redirects

### Describe the bug

Any route does not work in deployment and fails with Access denied error. I tried this fix [https://stackoverflow.com/questions/63025997/getting-an-access-denied-error-when-i-reload-my-react-app-on-aws-amplify](url) of creating a custom rewrite to /index.html which makes the route to work but instead only index.html file loads up and not what is specified by the route.

### Expected behavior

Routes should work normally

### Reproduction steps

1. Create a V12+ Nextjs app on local, create routes
2. Deploy using next build & next export
3. Specify the custom domain and also it's redirections from https:// to https://www.

### Build Settings

```yaml
version: 1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: out
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```

### Log output

![image](https://user-images.githubusercontent.com/108795907/196606552-5512d8a9-4722-470a-b525-9123e15f3b7e.png)

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Next.js v12+ app deployment with `next build` and `next export`, then inspect the Amplify Hosting deployment and redirect configuration described in the issue. Compare the exported routes with the access-denied response and the `/index.html` rewrite; done means each deployed route loads its requested page rather than only the index page.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, nextjs
Domain
cloud, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.