AWS Cloud Formation; Breaking up template into several files and passing in variables with cfn-include

Viewed 9632

I'm running into some issues with my aws cloud formation template.

I have a general staging.yaml file where I define all my lambdas and apis. Problem is, that file has gotten WAY too big. So I decided to use this package: https://www.npmjs.com/package/cfn-include. So I can break the file up into several templates. As such:

Fn::Merge:
 - !Include ./templates/api-lambdas/accounts.yaml
 - !Include ./templates/api-lambdas/officers.yaml
 - !Include ./templates/api-lambdas/branches.yaml

My question is, is there any way of passing variables into these includes? I.E:

- !include ./templates/api-lambdas/accounts/yaml, variables: {database: databaseName, environment: staging}

And the accounts.yaml would look like this:

Environment:
 Variables:
  ENV: ${environment}
  DB_NAME: ${databaseName}

Thanks!

2 Answers

There is one more alternative: cfpack.js tool. It allows you to split your gigantic template into smaller templates that will be combined into one and deployed to your CloudFormation stack.

Related