aws cloudformation -resource property error

时间:2017-08-04 12:37:50

标签: amazon-cloudformation

I have defined my parameters like this:

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

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

and referring the above parameters in "resources" section like below:

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

and while executing this I am getting the below error.

AWS::EC2::SecurityGroup InstanceSecurityGroup "Value of property VpcId must be of type String"

Note: I have only default VPC available which is not taken as string? any solutions to this issue...

2 个答案:

答案 0 :(得分:0)

安全组要求VpcId是一个字符串,属性是一个数组列表,所以你需要将属性更改为Type:String,或者使用 Fn::Select功能。

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

列表 - 一系列VPC ID

{
  "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

答案 1 :(得分:0)

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

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