amazon-web-services - 错误 !!! CloudFormation 模板验证

标签 amazon-web-services aws-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"
        }
      }
    }
  },
}

最佳答案

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

关于amazon-web-services - 错误 !!! CloudFormation 模板验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38648108/

相关文章:

amazon-web-services - Amazon Cognito - 多语言电子邮件

amazon-web-services - cloudformation模板中ssm参数的条件值

amazon-web-services - 导出 CDK 生成的 InternetGateway 资源 [AWS Cloudformation]

amazon-ec2 - 为什么我的 Ubuntu EC2 实例的 DataUser 部分中的脚本没有运行?我正在使用云信息

php - Laravel 与 MySQL 的连接在迁移时有效,但在 Controller 中无效

amazon-web-services - 何时在 Packer 与 Terraform 中进行配置?

javascript - 从另一个未被调用的 Lambda 函数中调用 Lambda 函数

amazon-web-services - 创建仅限 CloudFormation 的 AWS 策略

amazon-web-services - AWS Cloudformation 上的 Content-Type 出现错误

mysql - 尝试增加 RDS MySQL 实例上的存储时出错