我正在编写一个cloudformation模板,并且有一个参数来接受AWS资源的一组配置值。其中一个值为None
,如AWS文档中所指定。但是,当我将null
输入到cloudformation中时,堆栈失败并显示:
Template validation error: [/Parameters/.../AllowedValues/1] 'null' values are not allowed in templates.
例如,为弹性beantalk设置许多配置之一,默认为None
:
Parameters:
EC2KeyPairName:
Description: EC2 key pair name for SSH access
Type: AWS::EC2::KeyPair::KeyName
Default: null
Resources:
Type: AWS::ElasticBeanstalk::ConfigurationTemplate
Properties:
ApplicationName: !Ref Application
SolutionStackName: !FindInMap [ StackMap, !Ref StackType, stackName ]
OptionSettings:
- Namespace: aws:autoscaling:launchconfiguration
OptionName: EC2KeyName
Value: !Ref EC2KeyPairName
如何使用None
值作为参数的选项之一?
答案 0 :(得分:1)
https://cloudonaut.io/optional-parameter-in-cloudformation/的帖子提供了解决方案。
使用AWS::NoValue
设置cloudformation模板的None值。
答案 1 :(得分:0)
在模板中定义参数 下面的示例声明一个名为InstanceTypeParameter的参数。此参数使您可以为创建或更新堆栈时要使用的堆栈指定Amazon EC2实例类型。
请注意,InstanceTypeParameter的默认值为t2.micro。除非提供其他值,否则这是AWS CloudFormation用于供应堆栈的值。
Parameters:
InstanceTypeParameter:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- m1.small
- m1.large
Description: Enter t2.micro, m1.small, or m1.large. Default is t2.micro.
参数的一般要求 使用参数时,需要满足以下要求:
AWS CloudFormation模板中最多可以包含60个参数。
必须为每个参数指定一个逻辑名称(也称为逻辑ID),该名称必须为字母数字,并且在模板内的所有逻辑名称中都是唯一的。
必须为每个参数分配AWS CloudFormation支持的参数类型。有关更多信息,请参见Type。
必须在运行时为每个参数分配一个值,AWS CloudFormation才能成功配置堆栈。您可以选择指定一个默认值供AWS CloudFormation使用,除非提供了另一个值。
必须在同一模板内声明和引用参数。您可以从模板的“资源和输出”部分中引用参数。
请参阅:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html