首页 文章

aws cloudformation -resource属性错误

提问于
浏览
0

我已经定义了这样的参数:

{
    "PrivateSubnets":{
       "Description":"db subnetlist",
       "Type": "List<AWS::EC2::Subnet::Id>"
    },

    "VPCLIST": {
       "Description": "VPC list",
       "Type": "List<AWS::EC2::VPC::Id>"
    }
}

并在“资源”部分中引用上述参数,如下所示:

"InstanceSecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "VpcId" : {"Ref": "VPCLIST"} ,
        "GroupDescription" : "Enable 3306/80/SSH access via port 22"
}

在执行此操作时,我收到以下错误 .

AWS :: EC2 :: SecurityGroup InstanceSecurityGroup“属性值VpcId必须是String类型”

注意:我只有默认的VPC可用,不作为字符串?解决这个问题的任何方法......

2 回答

  • 0

    安全组要求VpcId是一个字符串,该属性是一个数组列表,因此您需要将该属性更改为Type:String,或使用Fn::Select函数 .

    { "Fn::Select" : [ 0, VPCLIST ] }
    

    清单 - An array of VPC IDs

    {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
         "GroupName" : String,
         "GroupDescription" : String,
         "SecurityGroupEgress" : [ Security Group Rule, ... ],
         "SecurityGroupIngress" : [ Security Group Rule, ... ],
         "Tags" :  [ Resource Tag, ... ],
         "VpcId" : String
      }
    }
    

    http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html

  • 0

    正确的方法是进行此更改:

    {
      "PrivateSubnets": {
        "Description":"db subnetlist",
        "Type": "AWS::EC2::Subnet::Id"
      },
      "VPCLIST": {
        "Description": "VPC list",
        "Type": "AWS::EC2::VPC::Id"
      }
    }
    

相关问题