Cloudformation 不支持List<AWS::Batch::JobDefinition::Environment>
(请参阅https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html)
有几种方法可以解决您的问题
请注意,我更熟悉使用 yaml 和 jinja,但波纹管也应该适用于对流层,我会在有机会时添加示例
Sceptre_user_data
在config/<stack_name>.yaml
添加
sceptre_user_data:
JobDefinitionEnvironment:
- <list-goes-here-as-yaml/json>
在cfn/<template>.yaml.j2
添加
myBatchJob
Type: AWS::Batch::JobDefinition
Properties:
Environment:
{{ sceptre_user_data.JobDefinitionEnvironment }}
本国的
原生做,可以使用Type: CommaDelimitedList
和选择,这个有点麻烦
Parameters:
BatchEnvironmentSetting1:
Type: CommaDelimitedList
Default: MySetting,MyValue
Resources:
myBatchJob:
Type: AWS::Batch::JobDefinition
Properties:
Environment:
- Name: !Select [0, BatchEnvironmentSetting]
Value: !Select [1, BatchEnvironmentSetting]
使用条件和循环
如果本机方法适合您,那么您可以将值设为可选(并且使用循环可以减少痛苦
Parameters:
{% for i in range(20) %}
BatchEnvironmentSetting{{ i }}:
Type: CommaDelimitedList
Default: ''
{% endfor %}
Conditions:
{% for i in range(20) %}
UseBatchEnvironmentSetting{{ i }}: !Not [!Equals [BatchEnvironmentSetting{{ i }}, '']]
{% endfor %}
Resources:
myBatchJob:
Type: AWS::Batch::JobDefinition
Properties:
Environment:
{% for i in range(20) %}
- !If
- UseBatchEnvironmentSetting{{ i }}
- Name: !Select [0, BatchEnvironmentSetting{{ i }}]
Value: !Select [1, BatchEnvironmentSetting{{ i }}]
- !Ref AWS::NoValue
{% endfor %}
这种循环是对流层可能使代码更清晰的地方之一,因为您可以拥有一个实现所有 3 个循环的 AddEnviornmentSetting 函数