Cannot access restApiId & restApiRootResourceId for cross stack reference in serverless yml

api-gateway

#1

Since I had an issue of 200 resource error, I found a way of using cross stack reference by dividing into different services. I managed to do that by using the cross-stack reference. The issue is I cannot give the restApiId & restApiRootResourceId dynamically. Right now, am statically setting ids into the service

Basically, the service-1 looks like,

provider:
  name: aws
  runtime: nodejs8.10
  apiGateway:
    restApiId: 
      Ref: ApiGatewayRestApi
    restApiResources:
      Fn::GetAtt:
          - ApiGatewayRestApi
          - RootResourceId
custom:
  stage: "${opt:stage, self:provider.stage}"

resources:
  Resources:
    ApiGatewayRestApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: ${self:service}-${self:custom.stage}-1

  Outputs:
    ApiGatewayRestApiId:
      Value:
        Ref: ApiGatewayRestApi
      Export:
        Name: ApiGatewayRestApi-restApiId

    ApiGatewayRestApiRootResourceId:
      Value:
         Fn::GetAtt:
          - ApiGatewayRestApi
          - RootResourceId 
      Export:
        Name: ApiGatewayRestApi-rootResourceId

And the service-2 looks like this,

provider:
  name: aws
  runtime: nodejs8.10
  apiGateway-shared:
    restApiId:
      'Fn::ImportValue': ApiGatewayRestApi-restApiId
    restApiRootResourceId:
      'Fn::ImportValue': ApiGatewayRestApi-rootResourceId

As the above service-2 config, I cannot reference the Ids. FYI: Both services are in different files. So How what’s wrong with this approach?