CloudFormation提供"无效的模板属性或属性"错误

时间:2017-07-22 17:29:17

标签: amazon-cloudformation

我得到"无效的模板属性或属性[TestLambda]"来自以下的cloudformation模板。我用在线json验证器验证了json。我已经尝试逐个删除属性,但仍然会收到错误。错误消息在诊断问题时毫无用处。

任何人都可以看到问题所在吗?

感谢。

{
  "Parameters": {
    "DeploymentBucket": {
      "Type": "String",
      "Description": "S3 bucket name where built artifacts are deployed"
    },
    "ProjectVersion": {
      "Type": "String",
      "Description": "Project Version"
    },
    "DeploymentTime": {
      "Type": "String",
      "Description": "It is a timestamp value which shows the deployment time. Used to rotate sources."
    },
    "DomainName": {
      "Type": "String",
      "Description": "Domain Name to serve the application"
    },
    "CloudSearchDomain": {
      "Type": "String",
      "Description": "Endpoint Name for CloudSearch domain"
    }
  },
  "Resources": {
    "LambdaExecutionRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "Path": "/",
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "lambda.amazonaws.com",
                  "apigateway.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "ManagedPolicyArns": [
          "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
        ]
      }
    },
    "LambdaCustomPolicy": {
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyName": "LambdaCustomPolicy",
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": [
                "s3:ListBuckets"
              ],
              "Resource": "*"
            }
          ]
        },
        "Roles": [
          {
            "Ref": "LambdaExecutionRole"
          }
        ]
      }
    }
  },
  "TestLambda": {
    "Type": "AWS::Lambda::Function",
    "Properties": {
      "Handler": "com.serverlessbook.lambda.test.Handler",
      "Runtime": "java8",
      "Timeout": "300",
      "MemorySize": "1024",
      "Description": "Test lambda",
      "Role": {
        "Fn::GetAtt": [
          "LambdaExecutionRole",
          "Arn"
        ]
      },
      "Code": {
        "S3Bucket": {
          "Ref": "DeploymentBucket"
        },
        "S3Key": {
          "Fn::Sub": "artifacts/lambda-test/${ProjectVersion}/${DeploymentTime}.jar"
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

TestLambda资源实际上在resources JSON对象之外。因此,它在AWS End的JSON验证失败,并带有意外的属性。

TestLambda内移动resources将解决此问题。

{
  "Parameters": {
    "DeploymentBucket": {
      "Type": "String",
      "Description": "S3 bucket name where built artifacts are deployed"
    },
    "ProjectVersion": {
      "Type": "String",
      "Description": "Project Version"
    },
    "DeploymentTime": {
      "Type": "String",
      "Description": "It is a timestamp value which shows the deployment time. Used to rotate sources."
    },
    "DomainName": {
      "Type": "String",
      "Description": "Domain Name to serve the application"
    },
    "CloudSearchDomain": {
      "Type": "String",
      "Description": "Endpoint Name for CloudSearch domain"
    }
  },
  "Resources": {
    "LambdaExecutionRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "Path": "/",
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "lambda.amazonaws.com",
                  "apigateway.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "ManagedPolicyArns": [
          "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
        ]
      }
    },
    "LambdaCustomPolicy": {
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyName": "LambdaCustomPolicy",
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": [
                "s3:ListBuckets"
              ],
              "Resource": "*"
            }
          ]
        },
        "Roles": [
          {
            "Ref": "LambdaExecutionRole"
          }
        ]
      }
    },
    "TestLambda": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Handler": "com.serverlessbook.lambda.test.Handler",
        "Runtime": "java8",
        "Timeout": "300",
        "MemorySize": "1024",
        "Description": "Test lambda",
        "Role": {
          "Fn::GetAtt": [
            "LambdaExecutionRole",
            "Arn"
          ]
        },
        "Code": {
          "S3Bucket": {
            "Ref": "DeploymentBucket"
          },
          "S3Key": {
            "Fn::Sub": "artifacts/lambda-test/${ProjectVersion}/${DeploymentTime}.jar"
          }
        }
      }
    }
  }
}

希望这会有所帮助。