Cloudformation模板中参数存储中EC2实例类型的动态参考

时间:2018-12-10 20:38:06

标签: amazon-cloudformation

我在确定如何直接从参数存储区引用EC2实例类型参数时遇到一些困难。我搜索过高低,但是没有运气。

我可以使用我的方法引用其他参数,例如EC2KeyPair。

我首先使用以下命令在参数存储中创建一个参数。 aws ssm put-parameter --name myEC2TypeDev --type String --value "t2.small"

在CF模板中,我定义了InstanceType参数。

"InstanceType" : {
  "Description" : "WebServer EC2 instance type",
  "Type" : "AWS::SSM::Parameter::Value<String>",
  "Default" : "myEC2TypeDev",
  "AllowedValues" : [ "t1.micro", "t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "m1.small", "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge", "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge", "r5.large", "c5.large", "c5.xlarge", "c1.medium", "c1.xlarge", "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge", "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge", "g2.2xlarge", "g2.8xlarge", "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge", "i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge", "d2.xlarge", "d2.2xlarge", "d2.4xlarge", "d2.8xlarge", "hi1.4xlarge", "hs1.8xlarge", "cr1.8xlarge", "cc2.8xlarge", "cg1.4xlarge"],
  "ConstraintDescription" : "must be a valid EC2 instance type."
}

执行模板时,返回以下错误:

  

调用UpdateStack时发生错误(ValidationError)   操作:参数InstanceType未能满足约束:必须   是有效的EC2实例类型。

1 个答案:

答案 0 :(得分:0)

如果您的资源类型存储在SSM(例如AWS::SSM::Parameter::Value)上,则提供的值必须是SSM(例如myEC2TypeDev)上参数的名称。因此,您的AllowedValues列表可能会引起冲突并引发错误。

请删除AllowedValues属性,然后重试。