Concat multiple function Files


#1

Hey fellas,

I have a base code with some legacy apis, and I’m trying to unify all in one container repository (with git subrepo) and creating one unique serverless.yml file in this container.

I’m trying to do the following in my serverless file:

functions: 
  ${file(api-1/functions.yml)}
  ${file(api-2/functions.yml)}

Inside this functions.yml is simply the function declaration like so:

users:
  DependsOn: RedisInstance
  handler: api-1/handler.index
  timeout: 30
  vpc:
    securityGroupIds:
      - Ref: RedisSecurityGroup
    subnetIds:
      - Ref: PrivateSubnet
  events:
    - http: any {proxy+}
  environment:
    stage: ${opt:stage}

I’m getting the error below when I try to do that:

Serverless Error ---------------------------------------

Trying to populate non string value into a string for variable ${file(api-front/functions.yml)}. Please make sure the value of the property is a string.

But when I remove one of the file its working as expected:

functions: 
  ${file(api-1/functions.yml)}

Is there a way to concatenate multiple .yml files?

Thanks!


#2

Hmm, sounds like you’ve uncovered an edge-case in the variable rendering - it just doesn’t make sense that removing one line would “fix” the problem.

I think a GH issue is your best bet.


#3

Thanks! I’m opening an issue there!