# Micro services with shared API Gateway

**URL:** <https://forum.serverless.com/t/micro-services-with-shared-api-gateway/6486>\
**Category:** Serverless Framework\
**Tags:** api-gateway\
**Created:** [November 18, 2018, 6:26pm UTC](https://forum.serverless.com/t/micro-services-with-shared-api-gateway/6486 "2018-11-18T18:26:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrsollis](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mrsollis/32/2757_2.png) [@mrsollis](https://forum.serverless.com/u/mrsollis)\
**Post date:** [November 18, 2018, 6:26pm UTC](https://forum.serverless.com/t/micro-services-with-shared-api-gateway/6486/1 "2018-11-18T18:26:42Z")

</div>

I have not been able to get Resources/Outputs/Exports to work in an effort to use multiple serverless configs that build out micro services to a single api gateway. According to this [issue/discussion](https://github.com/serverless/serverless/issues/3078) this should now work.

i’m sure its my config, but I have tried the documented way from [this link](https://serverless.com/framework/docs/providers/aws/events/apigateway/#share-api-gateway-and-api-resources)… I am getting the error `The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template`

I would be deeply grateful for any advice… thank you. This is the config I am using:

```auto
service: api-model 
frameworkVersion: '^1.33.0'

provider:
  name: aws
  runtime: nodejs8.10
  apiName: myapp-api-${opt:stage,'dev'}
  
  Resources:
    Outputs:
      apiGatewayRestApiId:
        Value:
          Ref: ApiGatewayRestApi
        Export:
          Name: apiGateway-restApiId
      apiGatewayRestApiRootResourceId:
        Value:
          Fn::GetAtt:
            - ApiGatewayRestApi
            - RootResourceId
        Export:
          Name: apiGateway-rootResourceId

  apiGateway:
    restApiId:
      Ref: ApiGatewayRestApi
    restApiResources:
      Fn::GetAtt:
        - ApiGatewayRestApi
        - RootResourceId

functions:
  api-model-read:
    environment:
      DEBUG: 'false'
    events:
      - http:
          path: /data/model
          method: get
      - http:
          path: /data/model/{modelId}
          method: get
          request:
            parameters:
              paths:
                modelId: true

    handler: read.handler
    memorySize: 128
    name: api-${opt:stage, 'dev'}-model-read
    timeout: 30

```

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [November 19, 2018, 3:34am UTC](https://forum.serverless.com/t/micro-services-with-shared-api-gateway/6486/2 "2018-11-19T03:34:00Z")

</div>

The `Resources` need to go under a `resources` key in the `serverless.yml` for the service that creates the API GW. See [https://serverless.com/framework/docs/providers/aws/guide/resources#configuration](https://serverless.com/framework/docs/providers/aws/guide/resources#configuration)

You then import it using the `${cf:...}` variables syntax into other services. See [https://serverless.com/framework/docs/providers/aws/guide/variables#reference-cloudformation-outputs](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-cloudformation-outputs)

---

<div class="post-metadata">

**Author:** ![mrsollis](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mrsollis/32/2757_2.png) [@mrsollis](https://forum.serverless.com/u/mrsollis)\
**Post date:** [November 19, 2018, 10:21pm UTC](https://forum.serverless.com/t/micro-services-with-shared-api-gateway/6486/3 "2018-11-19T22:21:44Z")

</div>

Thank you. I added resources node, and I still get an error

`The CloudFormation template is invalid: Invalid template resource property ‘apiGatewayRestApiId’`

---

<div class="post-metadata">

**Author:** ![mrsollis](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mrsollis/32/2757_2.png) [@mrsollis](https://forum.serverless.com/u/mrsollis)\
**Post date:** [November 25, 2018, 4:45am UTC](https://forum.serverless.com/t/micro-services-with-shared-api-gateway/6486/4 "2018-11-25T04:45:15Z")

</div>

For some reason, when deploying the original “service a” with functions at the same time was causing my error. As soon as I created a separate sls deployment, one for just the API resource. The documentation worked, and I can treat all of my micro-services with the referenced out api id.

Thanks for your help!
