1

I am trying to set up my serverless.yml file with only an API Gateway, and there are several resources that I need to reuse throughout the file, and I'd like to not copy and paste the same lines of code per resource like 100 times.

For example, I want to reuse TestId resource below and dynamically pass in the Ref under ParentId so I can reuse the resource for multiple parent resources. How can I do that?

TestResource:
  Type: AWS::ApiGateway::Resource
  Properties:
    ParentId:
      Fn::GetAtt:
        - TestApi
        - RootResourceId
    PathPart: test
    RestApiId:
      Ref: TestApi
TestId:
  Type: AWS::ApiGateway::Resource
  Properties:
    ParentId:
      Ref: TestResource
    PathPart: '{id}'
    RestApiId:
      Ref: TestApi

Ideally I would want the resuable TestId resource in a separate file and then reference it, and also pass in the dynamic value that I want to insert in. Something like:

TestId: ${file(testid.yml):TestId} somehow override the TestId.Properties.ParentId.Ref: <somevalue>

Does anyone know if this is possible?

noobprogrammer
  • 345
  • 1
  • 6
  • 20

1 Answers1

0

In case you are using NodeJs (if not maybe something like this exists in your programming language), I think you should take a look at this plugin : https://www.npmjs.com/package/yamlinc

It allow to compose YAML files using $include tag.

Hope this helps you.

NicoM
  • 125
  • 5