必须至少定义一个资源成员...云形成错误 ec2

pal*_*avi 8 cloud amazon-ec2 amazon-web-services aws-cloudformation

I tried other templates from the net but still getting the same error. Error
Run Code Online (Sandbox Code Playgroud)

消息:模板包含错误。:模板格式错误:必须至少定义一个资源成员。

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

"Description" : "TTND AWS CloudFormation template to launch first instance",

"Parameters" : {

"KeyName" : {
"Description" : "EC2 Key Pair for SSH Access",
"Default" : "sample",
"MinLength": "1",
"MaxLength": "64",
"AllowedPattern" : "[-_ a-zA-Z0-9]*",
"ConstraintDescription" : "can contain only alphanumeric characters, spaces, dashes and underscores."
},
"InstanceType" : {
"Description" : "Instance1 EC2 instance type",
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : [ "t2.micro","m1.small","m1.medium","m1.large"],
"ConstraintDescription" : "must be a valid EC2 instance type."
}
},
"Mappings" : {
    "AWSInstanceMapping" : {
      "t2.micro"    : { "Arch" : "64" },
      "t2.small"    : { "Arch" : "64" },
      "t2.medium"   : { "Arch" : "64" },
      "t2.large"    : { "Arch" : "64" },
      "m3.medium"   : { "Arch" : "64" },
      "m4.large"   : { "Arch" : "64" },
      "m4.xlarge"  : { "Arch" : "64" },
      "m4.2xlarge"  : { "Arch" : "64" }
    }
    },

    "InstanceAMI" : {
      "us-east-1"      : { "64" : "ami-09ca8e1e" }
    },
Run Code Online (Sandbox Code Playgroud)

我尝试了其他网络模板,但遇到了同样的错误

"Resources" : {

    "VPC" : {
      "Type" : "AWS::EC2::VPC",
      "Properties" : {
        "CidrBlock" : "10.0.0.0/16",
        "Tags" : [
          {"Key" : "Application", "Value" : { "Ref" : "AWS::StackId"} },
          { "Key": "Name", "Value": "Project_VPC"},
          {"Key" : "Network", "Value" : "Public" }
        ]
      }
    },

    "PublicSubnet" : {
      "Type" : "AWS::EC2::Subnet",
      "Properties" : {
        "VpcId" : { "Ref" : "VPC" },
        "CidrBlock" : "10.0.0.0/24",
        "Tags" : [
          {"Key" : "Application", "Value" : { "Ref" : "AWS::StackId"} },
          {"Key" : "Network", "Value" : "Public" },
          { "Key": "Name", "Value": "Project_Public_Subnet"}
        ]
      }
    },

    "InternetGateway" : {
      "Type" : "AWS::EC2::InternetGateway",
      "Properties" : {
        "Tags" : [
          {"Key" : "Application", "Value" : { "Ref" : "AWS::StackId"} },
          {"Key" : "Network", "Value" : "Public" },
          { "Key": "Name", "Value": "Project_Internetgateway"}
        ]
      }
    },

    "AttachGateway" : {
       "Type" : "AWS::EC2::VPCGatewayAttachment",
       "Properties" : {
         "VpcId" : { "Ref" : "VPC" },
         "InternetGatewayId" : { "Ref" : "InternetGateway" }
       }
    },
"PublicRouteTable" : {
      "Type" : "AWS::EC2::RouteTable",
      "Properties" : {
        "VpcId" : {"Ref" : "VPC"},
        "Tags" : [
          {"Key" : "Application", "Value" : { "Ref" : "AWS::StackId"} },
          {"Key" : "Network", "Value" : "Public" },
          { "Key": "Name", "Value": "cloudwords_public_routetable"}
        ]
      }
    },                                                           
Run Code Online (Sandbox Code Playgroud)

我为发布它而删除的一些代码给出了大的代码错误,所以

"Outputs" : {
 "InstanceId" : {
 "Description" : "InstanceId of the newly created instance",
 "Value" : { "Ref" : "Instance" }
 },
    }
}
Run Code Online (Sandbox Code Playgroud)

如果有人有使用 CloudFormation 模板启动 AWS EC2 实例的简单模板,请发布

Tom*_*Tom 5

您的示例似乎没有定义任何AWS::EC2::Instance资源,这些资源告诉 CloudFormation 配置 EC2 实例。

这是一个非常简约的 CloudFormation 模板,它将创建一个 t2.micro 实例。查看AWS::EC2::Instance 资源定义,了解有关可以添加哪些属性以对其进行自定义的详细信息。

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "ExampleEc2Instance": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "InstanceType": "t2.micro",
        "ImageId" : "ami-a0cfeed8"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

为特定的操作系统、配置和区域寻找有效的 AMI 可能有点棘手。本演练讨论了使用 AWS Lambda 自动查找 AMI 的策略。