AWS cloudformation 错误:模板验证错误:模板参数属性无效

问题描述 投票:0回答:9

我正在尝试创建要使用的 cloudformation 模板,但我不断收到上述错误。 这是我的模板的片段:

"Mappings" : {
    "AWSInstanceType2Arch" : {
            "t1.micro" : { "Arch" : "64" },
            "m1.small" : { "Arch" : "64" },
            "m1.medium" : { "Arch" : "64" },
            "m1.large" : { "Arch" : "64" },
            "m1.xlarge" : { "Arch" : "64" },
            "m2.xlarge" : { "Arch" : "64" },
            "m2.2xlarge" : { "Arch" : "64" },
            "m2.4xlarge" : { "Arch" : "64" },
            "m3.xlarge" : { "Arch" : "64" },
            "m3.2xlarge" : { "Arch" : "64" },
            "c1.medium" : { "Arch" : "64" },
            "c1.xlarge" : { "Arch" : "64" },
            "cc1.4xlarge" : { "Arch" : "64HVM" },
            "cc2.8xlarge" : { "Arch" : "64HVM" },
            "cg1.4xlarge" : { "Arch" : "64HVM" }
        },
    "AWSRegionArch2AMI" : {
                "us-west-2": {"AMI": "ami-1b3b462b"}
         }
     },

  "Resources": {
    "Ec2Instance" : {
          "Type" : "AWS::EC2::Instance",
    "Properties": {
        "ImageId": { "Fn::FindInMap": [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" },
        { "Fn::FindInMap": [ "AWSInstanceType2Arch", {"Ref": "InstanceType"}, "Arch" ] } ] },
            "InstanceType": {"Ref": "InstanceType"},
            "SecurityGroups": [ { "Ref": "SecurityGroups"} ],
            "KeyName": { "Ref": "KeyName" },
            "Tags": [ { "Key": "Name", "Value": { "Ref": "InstanceName" } } ] }
    },

我在底部发生了更多事情,例如要执行的 bash 脚本,但我无法通过这个问题。我错过了什么?

validation templates amazon-web-services amazon-ec2
9个回答
15
投票

我在寻找相同错误消息的解决方案时遇到了这个问题。

就我而言,我收到错误:

模板参数属性“Properties”无效

这是因为我将资源定义放置在模板的“Parameters”: { } 部分而不是“Resources”: { } 部分中。

错误消息是这样的,因为资源有一个“属性”部分,但“属性”对于参数无效。


5
投票

当我尝试将输出添加到模板时,我遇到了相同的错误消息。

$ aws cloudformation validate-template --template-body "$(cat aws/vpc/production.template)"

A client error (ValidationError) occurred when calling the ValidateTemplate operation: Invalid template resource property 'InfrastructureIP'

我的问题是我在“资源”下添加了输出,而不是在之后。

不正确

{
 "AWSTemplateFormatVersion" : "2010-09-09",

  "Parameters" : {
    #Some parameters
  },

  "Resources" : {
    #Whole lot of resources
    "Outputs" : {
      "InfrastructureIP" : {
        "Description": "The private IP of Infrastructure",  
        "Value" : { "Fn::GetAtt" : [ "Infrastructure", "PrivateIp" ] }
      }
    }
  }
}

正确

{
 "AWSTemplateFormatVersion" : "2010-09-09",

  "Parameters" : {
    #Some parameters
  },

  "Resources" : {
    #Whole lot of resources
  },

  "Outputs" : {
    "InfrastructureIP" : {
      "Description": "The private IP of Infrastructure",  
      "Value" : { "Fn::GetAtt" : [ "Infrastructure", "PrivateIp" ] }
    }
  }
}

1
投票

我有一个类似于

security groups
的变量名称,我通过执行
securityGroups

摆脱了这个错误

检查您的 json 键是否有正确的命名约定


0
投票

是间距问题。固定的。模板可能很棘手。


0
投票

就我而言,我将模板文件中的输出引用为 [Output],而不是 [Outputs],从而导致了此问题。


0
投票

我在寻找问题解决方案时遇到了这个问题-

错误是无效的模板属性

就我而言,这是

spacing
问题。因此,在我的例子中,我们使用
jinja
来生成模板,而一种模板方法(生成
output
)没有适当的缩进或空间。几小时后解决问题后终于解决了。


0
投票

检查是否有任何空格缺失或任何名称错误的属性(请记住属性区分大小写)。 所以“属性”是正确的,但“属性”不是。 “KeyType”是正确的,但“keyType”不是。

所以,问题可能在于未遵循间距或命名约定


0
投票

我也有类似的情况,由于我是 Cloud Formation 的新手,所以我错过了查看从 Jenkins shell 脚本调用的 CLI 的详细信息。老实说,我没有完成对云形成的阅读,我开始使用它配置资源,所以我会推荐以下步骤

  1. 检查您调用云形成的方式,查找缩进或语法错误。最好的选择是使用文本编辑器,它可以帮助排除任何愚蠢的错误,就像我一样,我使用 Visual Studio Code 来编辑文件。
  2. 查看 Stack.yml 文件并确保项目在正确的空间中声明,在我的例子中,由于空格问题,堆栈被意外移动到父参数声明中

这是我的示例 stack.yml 以及我如何从 Jenkins 调用云形成

AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  ApplicationName:
    Type: String
  TemplateURL:
    Type: String
  TargetGroupArn:
    Type: AWS::SSM::Parameter::Value<String>
  EnvironmentFile:
    Type: String
  Image:
    Type: String
Resources:
  Stack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: !Ref TemplateURL
      Parameters:
        ApplicationName: !Ref ApplicationName
        Image: !Ref Image
        Cpu: 1024
        Memory: 2048
        DesiredCount: 1
        Port: 8001
        TargetGroupArn: !Ref TargetGroupArn
        EnvironmentFile: !Ref EnvironmentFile

调用部分是在 shell 脚本中完成的,该脚本在我的 Jenkins 管道中调用下面是执行云形成的示例命令。

# Deploy the stack
aws cloudformation deploy \
    --stack-name "$appName-$env" \
    --parameter-overrides \
        "ApplicationName=$appName" \
        "TemplateURL=$S3TemplateLocation" \
        "TargetGroupArn=$ThisAppTargetGroupArn" \
        "EnvironmentFile=arn:aws:s3:::$s3Object" \
        "Image=$image" \
    --template-file $stackFileLocationInYourWorkspace \
    --capabilities CAPABILITY_NAMED_IAM \
    --no-fail-on-empty-changeset

0
投票

参数和资源是两个不同的组件。参数部分末尾少了一个“}”。

© www.soinside.com 2019 - 2024. All rights reserved.