serverless-aws-documentation icon indicating copy to clipboard operation
serverless-aws-documentation copied to clipboard

Can't use Models defined as CloudFormation Output of different Stack

Open pj035 opened this issue 6 years ago • 9 comments

I have the following setup:

  • multiple stacks with shared API Gateway (see serverless docs)
  • stack 1 defines a specific model and exports it (see serverless docs)
  • stack 2 should make us of the model via Fn::ImportValue

Stack1:

custom:
  documentation:
    models:
      - name: BadRequest400ResponseJSON
        contentType: 'application/json'
        schema: ....

resources:
  Outputs:
     BadRequest400ResponseModel:
        Value: BadRequest400ResponseJSON
     Export:
        Name: BadRequest400ResponseModel-${self:provider.stage}

Stack2:

someFunction:
  handler: myHandler
  events:
    documentation:
      methodResponses:
        - statusCode: '400'
          responseModels:
            "application/json": 
              Fn::ImportValue: 'BadRequest400ResponseModel-${self:provider.stage}'

The deployment of stack 2 fails because of Template format error: Unresolved resource dependencies [[object Object], [object Object]Model] in the Resources block of the template. The CloudFormation Template contains for some resources the object

DependsOn: [
  "MyAweSomeModel1",
  "MyAwesomeModel2",
  "[object Object]Model", // <-- this causes the problem
]

The problem is line 59, which expects the resource to be a string. If it's an object (like in my case with { "Fn::ImportValue": "<my-export-name>" }, then it fails.

A simple workaround for me is to ignore objects in line 59 (i.e. don't add them as dependency).

pj035 avatar Mar 01 '18 15:03 pj035

The dependency is definitely needed, otherwise cloudfront won't build stuff in the right order. There needs to be special handling for your case. If the model is an object, don't add them to the dependencies.

Also a good first issue to work on :)

tchock avatar Mar 01 '18 18:03 tchock

Of course the dependency is required. Maybe I did not express myself correctly. In my case the resource already exists, because it has been created by a different stack. Therefore that certain object should not be added to the dependencies.

I don't know if every object should be omitted or if different kind of objects (i.e. a different key than Fn::ImportValue) have to be handled differently?!

pj035 avatar Mar 01 '18 19:03 pj035

Any update on this? With the #77 closed with the latest code we are now facing this issue. We have an errorModel defined in stack1 which we would like to import in stack 2 and we are not able to do it.

malikadit avatar Apr 05 '18 18:04 malikadit

+1 any update on this? Can not use this plugin with multi-stacks currently unless someone has a clever workaround.

AndrewFarley avatar Sep 24 '18 07:09 AndrewFarley

any update on this issue, or workaround !

daoudsh avatar Feb 21 '19 10:02 daoudsh

Currently not. We also don't have that much time to investigate this. So if someone finds something, it would be really cool that they could fix it and make a PR to this project :)

tchock avatar Feb 21 '19 10:02 tchock

+1 from me as well. I might be able to try and see if I can work on a fix soon.

gcampionpae avatar May 26 '20 09:05 gcampionpae

+1 any update on this? some workaround or solution ?

In my case, when it shares same RestAPI into multiple stacks, the documentation of the last version is overriding another stacks functions documentation on swagger file.

joaoluizhilario avatar Oct 29 '20 13:10 joaoluizhilario

Sorry the project that I was working on that would have allowed me to spend some time on this has been on hold. ATM, I just renamed the various components that were similar so they all had different names and didn't overwrite each other :/

gcampionpae avatar Oct 30 '20 08:10 gcampionpae