Can not find API Gateway resource from path — fail to share api gateway

I am trying to deploy a shared api gateway for multiple services, and I have deployed the api gateway, I have checked on aws cloudformation, it does exist, however when I try to deploy other services who are going to use the api gateway, it always shows Can not find API Gateway resource from path xxx.

I tried to find the reason and disconnect the network, then run sls deploy --force, it also shows the same error.

The serverless framework version is 1.57.0

the shared api gateway is defined as:

service: sso-server-api-gateway
frameworkVersion: ">=1.2.0 <2.0.0"

provider: 
  name: aws
  runtime: python3.7
  profile: self
  region: ap-southeast-1
  stage: dev
  deploymentBucket: serverless-bucket-s3

resources:
  Resources:
    # root
    ApiGatewayRestApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: sso-server-api
        EndpointConfiguration: 
          Types:
            - REGIONAL
    # /sso
    ApiGatewaySSO:
      Type: AWS::ApiGateway::Resource
      Properties:
        RestApiId:
          Ref: ApiGatewayRestApi
        ParentId:
          Fn::GetAtt:
             - ApiGatewayRestApi
             - RootResourceId
        PathPart: "sso"
    # /sso/register
    ApiGatewaySSORegister:
      Type: AWS::ApiGateway::Resource
      Properties:
        RestApiId:
          Ref: ApiGatewayRestApi
        ParentId:
          Ref: ApiGatewaySSO
        PathPart: "register"

  Outputs:
    ApiGatewayRestApiId:
      Value:
        Ref: ApiGatewayRestApi
      Export:
        Name: ApiGatewayRestApiId
    ApiGatewayRootResourceId:
      Value: 
        Fn::GetAtt:
          - ApiGatewayRestApi
          - RootResourceId
      Export:
        Name: ApiGatewayRootResourceId
    ApiGatewaySSOId:
      Value:
        Ref: ApiGatewaySSO
      Export:
        Name: ApiGatewaySSOId
    ApiGatewaySSORegisterId:
      Value:
        Ref: ApiGatewaySSORegister
      Export:
        Name: ApiGatewaySSORegisterId

and the other service is defined as:

service: sso-server-entry
frameworkVersion: ">=1.2.0 <2.0.0"

provider:
  name: aws
  runtime: python3.7
  profile: self
  region: ap-southeast-1
  stage: dev
  deploymentBucket: serverless-bucket-s3
  apiGateway:
    restApiId: 
      Fn::ImportValue: ApiGatewayRestApiId
    restApiRootResourceId:
      Fn::ImportValue: ApiGatewayRootResourceId
    restApiResources:
      /sso:
        Fn::ImportValue: ApiGatewaySSOId
      /sso/register:
        Fn::ImportValue: ApiGatewaySSORegisterId

functions:
  hello:
    handler: handler.entry
    name: entry
    events:
      - http:
          method: post
          path: /sso/register
          cors: false

Hi Hugh,

Have you been able to resolve this issue. I am also getting the same error. My yaml is something like this.

provider:
  apiGateway:
    restApiId: xxxxxxxxxx
    # restApiRootResourceId: xxxxxxxxxx # Optional
    websocketApiId: xxxxxxxxxx
    description: Some Description
    restApiResources:
      /users/posts: xxxxxxxxxx
      /users/categories: xxxxxxxxx

I get the same error if I provide the restApiRootResourceId as well.

Thanks
Sushrut

Have you guys try

provider:
  apiGateway:
    restApiId: xxxxxxxxxx
    # restApiRootResourceId: xxxxxxxxxx # Optional
    websocketApiId: xxxxxxxxxx
    description: Some Description
    restApiResources:
      users/posts: xxxxxxxxxx
      users/categories: xxxxxxxxx

instead of

provider:
  apiGateway:
    restApiId: xxxxxxxxxx
    # restApiRootResourceId: xxxxxxxxxx # Optional
    websocketApiId: xxxxxxxxxx
    description: Some Description
    restApiResources:
      /users/posts: xxxxxxxxxx
      /users/categories: xxxxxxxxx

The slash makes the difference.

2 Likes

I am having problems getting the resource id for a path
I see examples like the above
restApiResources:
/users/posts: xxxxxxx

I assume you are filling in the xxxxx with the actual resource id or am I missing something around the x’s