CloudFormation 抛出“参数 groupId 的值 () 无效".值不能为空"启动 EC2 实例时 [英] CloudFormation throws "Value () for parameter groupId is invalid. The value cannot be empty" when launching EC2 instance

查看:60
本文介绍了CloudFormation 抛出“参数 groupId 的值 () 无效".值不能为空"启动 EC2 实例时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为公共子网中的单个 Linux EC2 实例编写完整的 CloudFormation 模板.我使用 AWS CloudFormation 模板来创建 EC2以安全组为起点的实例.此模板在您的默认 VPC 中启动一个实例.

I was wanting to write a complete CloudFormation template for a single Linux EC2 Instance in a public subnet. I used AWS CloudFormation template for creating an EC2 Instance with a Security Group as my starting point. This template launches an instance into your default VPC.

我的目标是拥有一个自包含模板,可以在新堆栈中创建所需的所有内容,但不会创建到默认 VPC 中.我想要一个新的 VPC、安全组、路由表、互联网网关、子网并启动一个新的 Linux EC2 实例.

My goal was to have a self contained template that creates everything needed in a new stack but not into the default VPC. I wanted a new VPC, Security Group, Route Table, Internet Gateway, Subnet and launch a new Linux EC2 instance.

所以我使用了上面的模板并添加了所需的资源并使用 Ref s链接它们.一切正常:VPC、子网、安全组、Internet GW、RouteTables 等.但我的 EC2 会出错,堆栈会回滚.

So I used the above template and added the needed resources and linked them using Ref s. Everything created fine: VPC, Subnet, Security Group, Internet GW, RouteTables, etc. But My EC2 would error out and the the stack would roll back.

状态原因是:

参数 groupId 的值 () 无效.值不能为空(服务:AmazonEC2;状态码:400;错误码:InvalidParameterValue;请求ID:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx)

CloudFormation 模板中的 EC2 资源如下所示:

The EC2 resource in the CloudFormation template looked like:

"EC2Instance" : {
        "Type" : "AWS::EC2::Instance",
        "Properties" : {
          "InstanceType" : { "Ref" : "InstanceType" },
          "SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
          "KeyName" : { "Ref" : "KeyName" },
          "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
                            { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }
          }
      }

错误消息不清楚该怎么做.

The error message was not clear on what to do.

推荐答案

在搜索错误消息后,我遇到很多人抱怨错误消息含糊不清,但没有针对 CloudFormation 模板中的 EC2 资源进行具体修复.

After searching on the error message, I came across many people grumbling about the vague error message, but no specific fix for the EC2 Resource in a CloudFormation template.

有人提到,当您不将 EC2 启动到默认 VPC 中时,您需要指定安全组 ID 而不是安全组名称.

Some people mentioned that when you don't launch an EC2 into the default VPC, you need to specify security group ids instead of the security group names.

检查 EC2 CloudFormation 资源类型的参考,有这个:

安全组

[EC2-Classic, default VPC] 安全组的名称.对于非默认 VPC,您必须改用安全组 ID.

[EC2-Classic, default VPC] The names of the security groups. For a nondefault VPC, you must use security group IDs instead.

在页面顶部,为 EC2 指定了安全组 ID,如下所示:

At the top of the page, the Security Group Ids are specified for an EC2 like so:

"SecurityGroupIds" : [ String, ... ],

所以我将我的 EC2 资源更改为以下内容:

So I changed my EC2 Resource to the following:

"EC2Instance" : {
        "Type" : "AWS::EC2::Instance",
        "Properties" : {
          "InstanceType" : { "Ref" : "InstanceType" },
          "SecurityGroupIds" : [ 
              { "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] }
            ],
          "SubnetId" : {"Ref":"TestSubnet"},
          "KeyName" : { "Ref" : "KeyName" },
          "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
                            { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }
          }
      },

它奏效了.

这篇关于CloudFormation 抛出“参数 groupId 的值 () 无效".值不能为空"启动 EC2 实例时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆