Amazon web services AWS Cloudformation-在YAML文件中导入Jinja定义的变量

Amazon web services AWS Cloudformation-在YAML文件中导入Jinja定义的变量,amazon-web-services,jinja2,amazon-cloudformation,Amazon Web Services,Jinja2,Amazon Cloudformation,我在Jinja文件中生成了一些Cloudwatch警报。我想在YML文件中使用其中一个警报来生成云。简单地放置DependsOn不起作用,因为processign失败,错误为 “StatusReason”:“模板格式错误:模板的资源块中未解析的资源依赖项[ABC.Alarm]”, 在YML文件中为Cloudformation部署导入Jinja变量的方法是什么 编辑: 我们的配置包含YML和Jinja文件,我不打算替换完整的模板。但只需使用Jinja文件中定义的参数 有多种方法可以使用yaml

我在Jinja文件中生成了一些Cloudwatch警报。我想在YML文件中使用其中一个警报来生成云。简单地放置
DependsOn
不起作用,因为processign失败,错误为


“StatusReason”:“模板格式错误:模板的资源块中未解析的资源依赖项[ABC.Alarm]”,

在YML文件中为Cloudformation部署导入Jinja变量的方法是什么

编辑:


我们的配置包含YML和Jinja文件,我不打算替换完整的模板。但只需使用Jinja文件中定义的参数

有多种方法可以使用yaml模板被Jinja取代

  • -需要最少代码的bash实用程序

  • 使用Python(jinja模块)+bash


您可能还不想生成CloudFormation模板。更好地利用

您可以使用预处理,甚至“执行”模板

Ansible具有cloudformation模块,您可以将要创建/更新的堆栈的名称传递给它,还可以传递模板参数

在Ansible playbook
实验中.yml

- hosts: localhost
  connection: local
  gather_facts: False

  tasks:
    - cloudformation:
        stack_name: experiments
        template: experiments-stack.yml
        template_parameters:
            MyParameter: MyParameterValue
...

Parameters:
    MyParameter:
        Type: String

Resources:
    Something:
        Type: ...
        Properties:
        PropertyName: !Ref MyParameter
CloudFormation堆栈模板
实验堆栈.yml

- hosts: localhost
  connection: local
  gather_facts: False

  tasks:
    - cloudformation:
        stack_name: experiments
        template: experiments-stack.yml
        template_parameters:
            MyParameter: MyParameterValue
...

Parameters:
    MyParameter:
        Type: String

Resources:
    Something:
        Type: ...
        Properties:
        PropertyName: !Ref MyParameter

使用ansible playbook/experiments.yml运行playbook,我不想替换完整的模板。但只需使用Jinja文件中定义的参数。