aws-amplify / aws-amplify/amplify-cli
gen2-migration generate/assess fails with "Root resource not found for REST API" on APIs with >25 resources (missing pagination)
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### How did you install the Amplify CLI?
NPM
### If applicable, what version of Node.js are you using?
22.22.3
### Amplify CLI Version
14.5.1
### What operating system are you using?
MacOs
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made
### Describe the bug
When running `amplify gen2-migration generate` I receive the error:
```
→ Planning failed
🛑 Root resource not found for REST API ''
```
`fetchRestApiRootResourceId()` in packages/amplify-cli/src/commands/gen2-migration/_common/aws-fetcher.ts (lines 192–198) calls API Gateway's GetResourcesCommand exactly once with no pagination:
```
public async fetchRestApiRootResourceId(restApiId: string): Promise {
const { items } = await this.clients.apiGateway.send(new GetResourcesCommand({ restApiId }));
const root = items?.find((r) => r.path === '/');
if (!root?.id) {
throw new AmplifyError('RestApiResourceNotFoundError', {
message: `Root resource not found for REST API '${restApiId}'`,
```
GetResources paginates server-side (default page size 25, returns a position token) and item ordering isn't guaranteed to put / first. On any REST API with more than ~25 resources, / can land past page 1, this call never follows position, and generate/assess fails even though the API and its root resource are completely healthy.
### Expected behavior
`amplify gen2-migration generate` is able to run without error on large REST APIs
### Reproduction steps
Any Gen1 REST API category with 25+ Lambda-backed paths reproduces this. In our case (75 resources), root resource sits at position 66 in id order — confirmed via direct aws apigateway get-resources --no-paginate returning only 25 items, no root, with a position token present signaling more pages.
### Project Identifier
_No response_
### Log output
```
# Put your logs below this line
```
### Additional information
_No response_
### Before submitting, please confirm:
- [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.
Contributor guide
Research direction
Start in packages/amplify-cli/src/commands/gen2-migration/_common/aws-fetcher.ts at fetchRestApiRootResourceId() and inspect the GetResourcesCommand response, including its position token. Reproduce with a REST API containing more than 25 resources, then verify that amplify gen2-migration generate or assess succeeds and locates the root resource on later pages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- api, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100