【问题标题】:JSON Format Error-Amzon EC2 instance creationJSON格式错误-Amzon EC2实例创建
【发布时间】:2014-09-05 19:51:06
【问题描述】:

我正在通过 Java Eclipse 创建 Amazon Stack。

下面的代码行抛出错误

csr.setTemplateURL("https://s3.amazonaws.com/cloudformation-templates-us-east-  1/AutoScalingMultiAZSample.template");

我得到的错误是:

捕获异常:参数:[KeyName] 必须具有值(服务:AmazonCloudFormation;状态代码:400;错误代码:ValidationError;请求 ID:9363d711-3535-11e4-8cf2-913ef42879cb) 响应状态码:400

我的 json 模板网址是 https://s3.amazonaws.com/cloudformation-templates-us-east-1/AutoScalingMultiAZSample.template

请帮助检测错误的确切来源。

【问题讨论】:

  • 为什么您的网址中嵌入了一串空白?这是这里的错字还是在您的源代码中的 URL 中?

标签: java json amazon-web-services amazon-ec2


【解决方案1】:

好的,我尝试使用在线验证器验证您的 json 架构。

http://jsonlint.com/

我刚刚复制了您的 json 架构并粘贴在那里。它说无效的模式期望 { 在第 1 行。好吧,我必须在你的模式之间加上左括号和右括号。但它又给出了错误。最后一行的额外括号}。所以我不得不删除它。然后验证了 json 模式。这意味着您在架构中的某个地方放置了一个额外的右括号}。

我认为你犯错的地方是:

"InstanceSecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "GroupDescription" : "Enable SSH access and HTTP from the load balancer only",
        "SecurityGroupIngress" : [ {
          "IpProtocol" : "tcp",
          "FromPort" : "22",
          "ToPort" : "22",
          "CidrIp" : { "Ref" : "SSHLocation"}
        },
        {
          "IpProtocol" : "tcp",
          "FromPort" : { "Ref" : "WebServerPort" },
          "ToPort" : { "Ref" : "WebServerPort" },
          "SourceSecurityGroupOwnerId" : {"Fn::GetAtt" : ["ElasticLoadBalancer", "SourceSecurityGroup.OwnerAlias"]},
          "SourceSecurityGroupName" : {"Fn::GetAtt" : ["ElasticLoadBalancer", "SourceSecurityGroup.GroupName"]}
        } ]
      }
    }//Extra Bracket i think so
  },

  "Outputs" : {
    "URL" : {
      "Description" : "The URL of the website",
      "Value" :  { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}]]}
    }
  }
}

【讨论】:

  • 即使在删除括号后,我在 eclipse 中也遇到了同样的错误。我验证了 jsonlint.com 中的架构,它在不删除括号的情况下显示有效。但如果删除括号,则显示为解析错误。请帮忙。
猜你喜欢
  • 2021-08-19
  • 1970-01-01
  • 2021-04-16
  • 1970-01-01
  • 1970-01-01
  • 2018-07-31
  • 1970-01-01
  • 1970-01-01
  • 2015-07-02
相关资源
最近更新 更多