CloudFormation模板格式错误:每个Parameters对象都必须包含Type成员

Ale*_*vey 0 amazon-web-services aws-cloudformation

我有以下非常简单的CloudFormation模板:

---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
  InstanceType:
    Description: 'EC2 Instance Type'
    Default: t2.micro
Resources:
  EC2Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      ImageId: ami-08589eca6dcc9b39c
      InstanceType: !Ref InstanceType
      KeyName: default
Run Code Online (Sandbox Code Playgroud)

在使用以下方法验证此模板时:

? aws cloudformation validate-template --template-body file://cloudformation.yml
Run Code Online (Sandbox Code Playgroud)

我收到以下神秘错误消息:

An error occurred (ValidationError) when calling the ValidateTemplate operation:
  Template format error: Every Parameters object must contain a Type member.           
Run Code Online (Sandbox Code Playgroud)

这是什么意思?我在Google上搜索了此错误消息,却一无所获。

Ale*_*vey 5

该错误消息可能会令人困惑-特别是在您有很多参数的情况下-并且似乎没有任何地方记录该错误消息。但是在文档中这里提到:

必须为每个参数分配AWS CloudFormation支持的参数类型。有关更多信息,请参见Type

因此,要修复此模板,只需添加一个类型:

---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
  InstanceType:
    Type: String  ## ADD THIS LINE
    Description: 'EC2 Instance Type'
    Default: t2.micro
Resources:
  EC2Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      ImageId: ami-08589eca6dcc9b39c
      InstanceType: !Ref InstanceType
      KeyName: default
Run Code Online (Sandbox Code Playgroud)

另请参阅堆栈溢出处的相关 问题