Serverless Framework Error: Single API Gateway Project - RootResourceId attribute of API Gateway RestAPI doesn't exist
Mia Lopez
I am having a problem deploying my application in AWS with CloudFormation using the Serverless Framework.
I am using the "Single API Gateway Project" strategy for the deployment. I have my Backend divided into services, each with its directory inside the repo and its serverless.yml file.
To have a single API Gateway for each one of them, I first deploy a root service that creates said API Gateway for me and outputs the ApiGatewayRestApiId and ApiGatewayRestApiRootResourceId as I could see in the following document of the same Serverless Framework:
My root service that creates the API Gateway is something like:
...
resources: Outputs: ApiGatewayRestApiId: Value: Ref: ApiGatewayRestApi Export: Name: ${self:provider.stage}-ApiGatewayRestApiId ApiGatewayRestApiRootResourceId: Value: Fn::GetAtt: - ApiGatewayRestApi - RootResourceId Export: Name: ${self:provider.stage}-ApiGatewayRestApiRootResourceId
...Then, from the rest of the microservices, I use those values by importing them as follows:
service: name
custom: APP_ENV: ${env:SERVERLESS_APP}
providers: apiGateway: restApiId: !ImportValue ${env:${self:custom.APP_ENV}_API_STAGE}-ApiGatewayRestApiId restApiRootResourceId: !ImportValue ${env:${self:custom.APP_ENV}_API_STAGE}-ApiGatewayRestApiRootResourceId
...I never had any problems deploying until today, when I tried to deploy only the root service. The error I am having is the following:
An error occurred: root-beta - Template error: RootResourceId attribute of API Gateway RestAPI d8zc1j912b doesn't exist.
I checked everywhere but I can't find the reason why I get this error.
- Operating System: linux
- Node Version: 13.10.0
- Framework Version: 1.60.0
- PluginVersion: 3.8.4
- SDK Version: 2.3.2
- Components Core Version: 1.1.2
- Components CLI Version: 1.6.0
1 Answer
Based on a comment I just read on Github, this is caused by an API that consists of more than 200 resources in total. CloudFormation (which is used to deploy serverless resources) only retrieves up to 8 pages of 25 resources to locate the root resource id, so if it happens to be on page 9+, it'll throw that error.
I'm not quite sure what the order of these resources is. In my own tests, sometimes it works, and other times it fails.
Original text from AWS (copied here in case the Github issue disappears):
... CloudFormation is making an API call with action “apiateway:GetResources” in order to get the root resource ID. This corresponds to the following API call [1]. This is a paginated response, meaning that it only returns resources 25 at a time (by default). Furthermore, to prevent throttling and time out issues, this is only checked a maximum of 8 pages deep. This means, that this root resource ID must be in the first 200 responses in order to get the root resource ID. Otherwise, it will fail to get this value.
...
The service team is aware of this issue and are working on a way to fix this. However, there is no ETA for this to be available.
Source: