错误!!! CloudFormation模板验证

时间:2016-07-28 23:02:16

标签: amazon-web-services amazon-cloudformation

我正在使用cloudformation模板设计redis集群,在模板验证过程中我遇到了这个错误“模板包含错误:模板格式错误:JSON格式不正确。(第151行,第2列) )

以下是cloudformation脚本

{
  "AWSTemplateFormatVersion": "2010-09-09",
   "Metadata": {
    "AWS::CloudFormation::Designer": {
      "f60e2d2e-b46b-48b1-88c8-eecce45d2166": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 320,
          "y": 70
        },
        "z": 2,
        "parent": "71508a33-8207-4580-8721-c3688c4a0353",
        "embeds": [],
        "ismemberof": [
          "a63aacbd-1c6e-4118-8bbe-08a5bc63052a",
          "55eb37aa-e764-49ac-b8fe-3eddb2ea77ad"
        ]
      },
      "a63aacbd-1c6e-4118-8bbe-08a5bc63052a": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 320,
          "y": 160
        },
        "z": 2,
        "parent": "71508a33-8207-4580-8721-c3688c4a0353",
        "embeds": []
      },
      "0291abc8-9c50-491b-8400-e1f7f8b22118": {
        "source": {
          "id": "f60e2d2e-b46b-48b1-88c8-eecce45d2166"
        },
        "target": {
          "id": "a63aacbd-1c6e-4118-8bbe-08a5bc63052a"
        },
        "z": 1
      },
      "55eb37aa-e764-49ac-b8fe-3eddb2ea77ad": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 440,
          "y": 70
        },
        "z": 2,
        "parent": "71508a33-8207-4580-8721-c3688c4a0353",
        "embeds": []
      },
      "7aa270dd-1131-4dc4-8913-dfaf44a3815d": {
        "source": {
          "id": "f60e2d2e-b46b-48b1-88c8-eecce45d2166"
        },
        "target": {
          "id": "55eb37aa-e764-49ac-b8fe-3eddb2ea77ad"
        },
        "z": 2
      },
      "71508a33-8207-4580-8721-c3688c4a0353": {
        "size": {
          "width": 610,
          "height": 600
        },
        "position": {
          "x": 20,
          "y": 10
        },
        "z": 1,
        "embeds": [
          "55eb37aa-e764-49ac-b8fe-3eddb2ea77ad",
          "a63aacbd-1c6e-4118-8bbe-08a5bc63052a",
          "f60e2d2e-b46b-48b1-88c8-eecce45d2166"
        ]
      }
    }
   },
   "Parameters" : {
     "CacheNodeType" : {
     "Description" : "The compute and memory capacity of the nodes in the Cache Cluster",
     "Type" : "String",
     "Default" : "cache.m3.medium",
     "AllowedValues" : ["cache.t2.micro", "cache.t2.small", "cache.t2.medium", 
      "cache.m3.medium", "cache.m3.large", "cache.m3.xlarge", "cache.m3.2xlarge",
      "cache.t1.micro", "cache.m1.small", "cache.m1.medium", "cache.m1.large",
      "cache.m1.xlarge", "cache.c1.xlarge", "cache.r3.large", "cache.r3.xlarge",
      "cache.r3.2xlarge", "cache.r3.4xlarge","cache.r3.8xlarge", "cache.m2.xlarge", 
      "cache.m2.2xlarge", "cache.m2.4xlarge"], 
      "ConstraintDescription" : "must select a valid Cache Node type."
     }
   },

   "Resources": {
    "RedisClusterReplicationGroup": {
      "Type": "AWS::ElastiCache::ReplicationGroup",
      "Properties": {
        "CacheParameterGroupName": {
        "Ref": "RedisClusterParameterGroup"
        },
        "CacheSubnetGroupName": {
        "Ref": "RedisClusterSubnetGroup"
        },
        "CacheNodeType" : { "Ref" : "CacheNodeType" },
        "Engine" : "redis",
        "EngineVersion" : "2.8.24",
        "NumCacheClusters" : 4,
        "Port" : 6879,
        "PreferredCacheClusterAZs" : ["us-east-1c","us-east-1d","us-east-1e"],
        "ReplicationGroupDescription" : "RedisClusterReplicationGroup",
        "SecurityGroupIds" : "sg-7ea72e07",
        "SnapshotRetentionLimit" : 0,
        "AutomaticFailoverEnabled" : true,
        "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "f60e2d2e-b46b-48b1-88c8-eecce45d2166"
        }
      }
    },
    "RedisClusterParameterGroup": {
      "Type": "AWS::ElastiCache::ParameterGroup",
      "Properties": {
        "CacheParameterGroupFamily" : "redis2.8",
        "CacheParameterGroupName" : "RedisClusterParameterGroup",
        "Description" :"RedisClusterParameterGroup"
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "a63aacbd-1c6e-4118-8bbe-08a5bc63052a"
        }
      }
    },
    "RedisClusterSubnetGroup": {
      "Type": "AWS::ElastiCache::SubnetGroup",
      "Properties": {
        "Description" : "RedisClusterSubnetGroups",
        "SubnetIds" : ["subnet-7854ab20", "subnet-eaa7039c", "subnet-988a00a5"]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "71508a33-8207-4580-8721-c3688c4a0353"
        }
      }
    }
  },
}

2 个答案:

答案 0 :(得分:2)

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Metadata": {
    "AWS::CloudFormation::Designer": {
      "f60e2d2e-b46b-48b1-88c8-eecce45d2166": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 320,
          "y": 70
        },
        "z": 2,
        "parent": "71508a33-8207-4580-8721-c3688c4a0353",
        "embeds": [],
        "ismemberof": [
          "a63aacbd-1c6e-4118-8bbe-08a5bc63052a",
          "55eb37aa-e764-49ac-b8fe-3eddb2ea77ad"
        ]
      },
      "a63aacbd-1c6e-4118-8bbe-08a5bc63052a": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 320,
          "y": 160
        },
        "z": 2,
        "parent": "71508a33-8207-4580-8721-c3688c4a0353",
        "embeds": []
      },
      "0291abc8-9c50-491b-8400-e1f7f8b22118": {
        "source": {
          "id": "f60e2d2e-b46b-48b1-88c8-eecce45d2166"
        },
        "target": {
          "id": "a63aacbd-1c6e-4118-8bbe-08a5bc63052a"
        },
        "z": 1
      },
      "55eb37aa-e764-49ac-b8fe-3eddb2ea77ad": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 440,
          "y": 70
        },
        "z": 2,
        "parent": "71508a33-8207-4580-8721-c3688c4a0353",
        "embeds": []
      },
      "7aa270dd-1131-4dc4-8913-dfaf44a3815d": {
        "source": {
          "id": "f60e2d2e-b46b-48b1-88c8-eecce45d2166"
        },
        "target": {
          "id": "55eb37aa-e764-49ac-b8fe-3eddb2ea77ad"
        },
        "z": 2
      },
      "71508a33-8207-4580-8721-c3688c4a0353": {
        "size": {
          "width": 610,
          "height": 600
        },
        "position": {
          "x": 20,
          "y": 10
        },
        "z": 1,
        "embeds": [
          "55eb37aa-e764-49ac-b8fe-3eddb2ea77ad",
          "a63aacbd-1c6e-4118-8bbe-08a5bc63052a",
          "f60e2d2e-b46b-48b1-88c8-eecce45d2166"
        ]
      }
    }
  },
  "Parameters": {
    "CacheNodeType": {
      "Description": "The compute and memory capacity of the nodes in the Cache Cluster",
      "Type": "String",
      "Default": "cache.m3.medium",
      "AllowedValues": [
        "cache.t2.micro",
        "cache.t2.small",
        "cache.t2.medium",
        "cache.m3.medium",
        "cache.m3.large",
        "cache.m3.xlarge",
        "cache.m3.2xlarge",
        "cache.t1.micro",
        "cache.m1.small",
        "cache.m1.medium",
        "cache.m1.large",
        "cache.m1.xlarge",
        "cache.c1.xlarge",
        "cache.r3.large",
        "cache.r3.xlarge",
        "cache.r3.2xlarge",
        "cache.r3.4xlarge",
        "cache.r3.8xlarge",
        "cache.m2.xlarge",
        "cache.m2.2xlarge",
        "cache.m2.4xlarge"
      ],
      "ConstraintDescription": "must select a valid Cache Node type."
    }
  },
  "Resources": {
    "RedisClusterReplicationGroup": {
      "Type": "AWS::ElastiCache::ReplicationGroup",
      "Properties": {
        "CacheParameterGroupName": {
          "Ref": "RedisClusterParameterGroup"
        },
        "CacheSubnetGroupName": {
          "Ref": "RedisClusterSubnetGroup"
        },
        "CacheNodeType": {
          "Ref": "CacheNodeType"
        },
        "Engine": "redis",
        "EngineVersion": "2.8.24",
        "NumCacheClusters": 4,
        "Port": 6879,
        "PreferredCacheClusterAZs": [
          "us-east-1c",
          "us-east-1d",
          "us-east-1e"
        ],
        "ReplicationGroupDescription": "RedisClusterReplicationGroup",
        "SecurityGroupIds": "sg-7ea72e07",
        "SnapshotRetentionLimit": 0,
        "AutomaticFailoverEnabled": true,
        "Metadata": {
          "AWS::CloudFormation::Designer": {
            "id": "f60e2d2e-b46b-48b1-88c8-eecce45d2166"
          }
        }
      }
    },
      "RedisClusterParameterGroup": {
        "Type": "AWS::ElastiCache::ParameterGroup",
        "Properties": {
          "CacheParameterGroupFamily": "redis2.8",
          "CacheParameterGroupName": "RedisClusterParameterGroup",
          "Description": "RedisClusterParameterGroup"
        },
        "Metadata": {
          "AWS::CloudFormation::Designer": {
            "id": "a63aacbd-1c6e-4118-8bbe-08a5bc63052a"
          }
        }
      },
      "RedisClusterSubnetGroup": {
        "Type": "AWS::ElastiCache::SubnetGroup",
        "Properties": {
          "Description": "RedisClusterSubnetGroups",
          "SubnetIds": [
            "subnet-7854ab20",
            "subnet-eaa7039c",
            "subnet-988a00a5"
          ]
        },
        "Metadata": {
          "AWS::CloudFormation::Designer": {
            "id": "71508a33-8207-4580-8721-c3688c4a0353"
          }
        }
      }
    }
  }

任何JSON解析器都会告诉您问题所在。最后一个元素不需要','并且JSON需要一个'}'才能正确验证。我没有检查脚本是否通过了云形式验证,但它通过了JSON解析

答案 1 :(得分:2)

避免这整套JSON错误的一种方法是切换到Cloudformation支持的YAML语法。您可以将JSON文档转换为YAML at https://www.json2yaml.com/ 然后就这样使用它。如果没有引号,大括号和逗号,我发现YAML更容易维护。