簡體   English   中英

錯誤!!! CloudFormation 模板驗證

[英]Error !!! CloudFormation template validation

我正在使用 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"
        }
      }
    }
  },
}

避免這整套 JSON 錯誤的一種方法是切換到 Cloudformation 支持的 YAML 語法。 您可以在https://www.json2yaml.com/將您的 JSON 文檔轉換為 YAML,然后使用它。 我發現 YAML 沒有引號、大括號和逗號更容易維護。

{
  "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 還需要一個 '}' 才能正確驗證。 我還沒有檢查腳本是否通過了 cloudformation 驗證,但是,它通過了 JSON 解析

除上述幾點外,在使用cloudformation模板創建堆棧之前,您可以在https://jsonformatter.curiousconcept.com/上檢查CF模板,以獲取有效且格式正確的json。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM