AWS CFN 错误“参数 groupName 不能与参数子网一起使用”

2023-12-06

使用以下 yaml 时出现错误。我检查了代码,但我不认为有任何问题。我的结构计划有一个带有 2 个公有子网和 2 个私有子网的 VPC。一个Web服务器实例将放置在公共子网2中。我认为该问题可能与实例创建有关,因为该错误是在实例创建过程中出现的。

Parameters:
  EnvironmentName:
    Description: An environment name that is prefixed to resource names
    Type: String

  KeyName:
    Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
    Type: AWS::EC2::KeyPair::KeyName
    ConstraintDescription: must be the name of an existing EC2 KeyPair.

  SSHLocation:
    Description: The IP address range that can be used to SSH to the EC2 instances
    Type: String
    MinLength: '9'
    MaxLength: '18'
    Default: 0.0.0.0/0
    AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
    ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.

  VpcCIDR:
    Description: Please enter the IP range (CIDR notation) for this VPC
    Type: String
    Default: 10.0.0.0/16

  PublicSubnet1CIDR:
    Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone
    Type: String
    Default: 10.0.0.0/24

  PublicSubnet2CIDR:
    Description: Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone
    Type: String
    Default: 10.0.2.0/24

  PrivateSubnet1CIDR:
    Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone
    Type: String
    Default: 10.0.1.0/24

  PrivateSubnet2CIDR:
    Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone
    Type: String
    Default: 10.0.3.0/24

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: !Ref VpcCIDR
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: Name
          Value: !Ref EnvironmentName

  InternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: !Ref EnvironmentName

  InternetGatewayAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      InternetGatewayId: !Ref InternetGateway
      VpcId: !Ref VPC

  PublicSubnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 0, !GetAZs '' ]
      CidrBlock: !Ref PublicSubnet1CIDR
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName} Public Subnet (AZ1)

  PublicSubnet2:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 1, !GetAZs  '' ]
      CidrBlock: !Ref PublicSubnet2CIDR
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName} Public Subnet (AZ2)

  PrivateSubnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 0, !GetAZs  '' ]
      CidrBlock: !Ref PrivateSubnet1CIDR
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName} Private Subnet (AZ1)

  PrivateSubnet2:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 1, !GetAZs  '' ]
      CidrBlock: !Ref PrivateSubnet2CIDR
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName} Private Subnet (AZ2)

  NatGateway1EIP:
    Type: AWS::EC2::EIP
    DependsOn: InternetGatewayAttachment
    Properties:
      Domain: vpc

  NatGateway2EIP:
    Type: AWS::EC2::EIP
    DependsOn: InternetGatewayAttachment
    Properties:
      Domain: vpc

  NatGateway1:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId: !GetAtt NatGateway1EIP.AllocationId
      SubnetId: !Ref PublicSubnet1

  NatGateway2:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId: !GetAtt NatGateway2EIP.AllocationId
      SubnetId: !Ref PublicSubnet2

  PublicRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName} Public Routes

  DefaultPublicRoute:
    Type: AWS::EC2::Route
    DependsOn: InternetGatewayAttachment
    Properties:
      RouteTableId: !Ref PublicRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway

  PublicSubnet1RouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref PublicRouteTable
      SubnetId: !Ref PublicSubnet1

  PublicSubnet2RouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref PublicRouteTable
      SubnetId: !Ref PublicSubnet2


  PrivateRouteTable1:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName} Private Routes (AZ1)

  DefaultPrivateRoute1:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PrivateRouteTable1
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref NatGateway1

  PrivateSubnet1RouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref PrivateRouteTable1
      SubnetId: !Ref PrivateSubnet1

  PrivateRouteTable2:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName} Private Routes (AZ2)

  DefaultPrivateRoute2:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PrivateRouteTable2
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref NatGateway2

  PrivateSubnet2RouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref PrivateRouteTable2
      SubnetId: !Ref PrivateSubnet2

  WebServerSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Enable HTTP access via port 80 and SSH access via port 22
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '80'
        ToPort: '80'
        CidrIp: 0.0.0.0/0
      - IpProtocol: tcp
        FromPort: '22'
        ToPort: '22'
        CidrIp: !Ref SSHLocation

  WebServerInstance:
    Type: AWS::EC2::Instance
    Metadata:
      Comment: Install a simple PHP application
      AWS::CloudFormation::Init:
        config:
          packages:
            yum:
              httpd: []
              php: []
          groups:
            apache: {}
          users:
            "apache":
              groups:
                - "apache"
          sources:
            "/home/ec2-user/aws-cli": "https://github.com/aws/aws-cli/tarball/master"
          files:
            "/tmp/cwlogs/apacheaccess.conf":
              content: !Sub |
                [general]
                state_file= /var/awslogs/agent-state
                [/var/log/httpd/access_log]
                file = /var/log/httpd/access_log
                log_group_name = ${AWS::StackName}
                log_stream_name = {instance_id}/apache.log
                datetime_format = %d/%b/%Y:%H:%M:%S
              mode: '000400'
              owner: apache
              group: apache
            "/var/www/html/index.php":
              content: !Sub |
                <?php
                echo '<h1>AWS CloudFormation sample PHP application for ${AWS::StackName}</h1>';
                ?>
              mode: '000644'
              owner: apache
              group: apache
            "/etc/cfn/cfn-hup.conf":
              content: !Sub |
                [main]
                stack=${AWS::StackId}
                region=${AWS::Region}
              mode: "000400"
              owner: "root"
              group: "root"
            "/etc/cfn/hooks.d/cfn-auto-reloader.conf":
              content: !Sub |
                [cfn-auto-reloader-hook]
                triggers=post.update
                path=Resources.WebServerHost.Metadata.AWS::CloudFormation::Init
                action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource WebServerHost --region ${AWS::Region}
              mode: "000400"
              owner: "root"
              group: "root"
          commands:
            test:
              command: "echo \"$MAGIC\" > test.txt"
              env:
                MAGIC: "I come from the environment!"
              cwd: "~"
          services:
            sysvinit:
              httpd:
                enabled: 'true'
                ensureRunning: 'true'
              sendmail:
                enabled: 'false'
                ensureRunning: 'false'
    CreationPolicy:
      ResourceSignal:
        Timeout: PT5M
    Properties:
      InstanceType: t2.micro
      KeyName:
        Ref: KeyName
      ImageId: ami-a4c7edb2
      SubnetId: !Ref PublicSubnet2
      SecurityGroups:
        - !Ref WebServerSecurityGroup
      UserData:
        "Fn::Base64":
          !Sub |
            #!/bin/bash -xe
            # Get the latest CloudFormation package
            yum update -y aws-cfn-bootstrap
            # Start cfn-init
            /opt/aws/bin/cfn-init -s ${AWS::StackId} -r WebServerHost --region ${AWS::Region} || error_exit 'Failed to run cfn-init'
            # Start up the cfn-hup daemon to listen for changes to the EC2 instance metadata
            /opt/aws/bin/cfn-hup || error_exit 'Failed to start cfn-hup'
            # All done so signal success
            /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource WebServerHost --region ${AWS::Region}

Outputs:
  VPC:
    Description: A reference to the created VPC
    Value: !Ref VPC

  PublicSubnets:
    Description: A list of the public subnets
    Value: !Join [ ",", [ !Ref PublicSubnet1, !Ref PublicSubnet2 ]]

  PrivateSubnets:
    Description: A list of the private subnets
    Value: !Join [ ",", [ !Ref PrivateSubnet1, !Ref PrivateSubnet2 ]]

  PublicSubnet1:
    Description: A reference to the public subnet in the 1st Availability Zone
    Value: !Ref PublicSubnet1

  PublicSubnet2:
    Description: A reference to the public subnet in the 2nd Availability Zone
    Value: !Ref PublicSubnet2

  PrivateSubnet1:
    Description: A reference to the private subnet in the 1st Availability Zone
    Value: !Ref PrivateSubnet1

  PrivateSubnet2:
    Description: A reference to the private subnet in the 2nd Availability Zone
    Value: !Ref PrivateSubnet2

安全组仅适用于默认 VPC 或 EC2-classic:

对于非默认 VPC,您必须使用安全组 ID反而。

因此它更好地使用安全组ID.

      SecurityGroupIds:
        - !GetAtt WebServerSecurityGroup.GroupId

还有你的WebServerSecurityGroup属于默认 VPC,但您的实例位于自定义 VPC 中。你需要VpcId对于您的安全组:

  WebServerSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Enable HTTP access via port 80 and SSH access via port 22
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '80'
        ToPort: '80'
        CidrIp: 0.0.0.0/0
      - IpProtocol: tcp
        FromPort: '22'
        ToPort: '22'
        CidrIp: !Ref SSHLocation
      VpcId: !Ref VPC

Your cfn-signal应该是(错误--resource):

/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource WebServerInstance --region ${AWS::Region}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AWS CFN 错误“参数 groupName 不能与参数子网一起使用” 的相关文章

随机推荐

  • 如何使用Python匹配文件并将其移动到相应的文件夹中

    我对编程相当陌生 这是我第一次尝试使用 Python 创建复杂的脚本 我创建的程序的目的是 浏览文件列表 单个文件夹中总共 360 个文件 提取文件名中的 3 个唯一字符并根据这 3 个字符创建一个文件夹 总共 60 个唯一文件夹 创建一个
  • 使用 IN 指令通过准备好的语句进行搜索

    我的目的是查找表中与存储在字符串中的集合匹配的所有项目 array array item1 item2 item3 item4 This is dynamically filled this is just an example in li
  • VS 2017 程序无法识别“scoped_lock”

    我在 VS 2017 中使用scoped locked 时遇到了问题 我相信我将它们追溯到
  • JavaFX 表列,SceneBuilder 未填充

    我一直在看教程 但似乎无法找到表格来填充 我也在使用 net beans 和 scenebuilder 任何帮助将不胜感激 奋斗了5个小时 这是我的代码Controller class public class FXMLDocumentCo
  • Mysql 无法连接,因为目标机主动拒绝

    我知道已经有很多人问过这个问题 但是这些人大多忘记了密码或被防火墙阻止 而我没有这种情况 我正在使用 php 进行开发 我需要连接到远程数据库以便让我的所有团队都可以使用它 localhost 一切正常 但是当我尝试切换时 它给了我这个错误
  • 类型错误:“模块”对象不可调用

    File C Users Administrator Documents Mibot oops blinkserv py line 82 in init self serv socket AF INET SOCK STREAM TypeEr
  • iBook 页面翻转过渡

    我正在尝试为 pdf 阅读器应用程序在横向模式下重新创建类似 iBook 的页面过渡 我只需要动画 不需要像 iBook 应用程序那样的触摸处理 用户通过简单的滑动即可翻页 我尝试了不同的示例代码 包括Leaves 但我找不到任何简单的东西
  • 在 M1 Mac 上的 Rosetta 2 模拟下,Ansible 返回的“ansible_machine”和“ansible_architecture”是什么

    在 M1 MacBook 上 ansible architecture and ansible machine返回相同的值arm64 shuuji3 momo mac dev playbook gt ansible m setup loca
  • 执行流程链

    public void ExecuteProcessChain string asProcesses string sInRedirect string sOutRedirect Process p1 new Process p1 Star
  • 如何获取外部控制器当前的$sce?

    为了获取控制器外部的当前 scope 我可以使用 var scope angular element ng controller ProductCtrl scope 如何获取当前控制器 sce The sce是一项服务 因此您可以使用注入器
  • 如何创建 .jar 文件?

    In the tutorial我发现jar文件可以通过以下方式创建 jar cf jar file input file s 但是 尚不清楚输入文件是什么 那是 java 文件还是 class 文件 从同一页面上的示例中 我可以假设应该是
  • json_encode 具有私有属性的对象数组

    我正在寻找一种对对象数组使用 json encode 的有效方法 我遇到的问题是我的对象都有私有属性 使用 getters 和 setters 并且 json encode 不会将它们拉进来 所以我为一个对象创建了一个 jsonSerial
  • Java 中 isDirectory 和 isFile 的 File 始终返回 false

    为什么文件返回 falseisFile 方法 即使它是文件 当它是目录时 它返回 falseisDirectory 难道我做错了什么 我测试的这些文件 目录不存在 我需要创建它们 所以这就是我测试是否应该使用的原因createFile or
  • 使用 jQuery 获取当前事件处理程序的值

    我可以通过调用使用 jQuery 设置 onclick 处理程序 id click function console log click 同样使用 jQuery 我如何获取当前正在处理 click 事件的函数的引用 原因是我有另一个对象 并
  • 当outputDirectory或outputFileName更改时启动调试应用程序时AS找不到apk

    我正在使用 Android Studio 来调试我的应用程序 由于某些原因 我必须更改默认输出 apk 目录和文件名 所以我在应用程序的build gradle脚本中更改了applicationVariants的outputDirector
  • Java While 循环中的字符串条件

    我试图提示用户给我三个字符串之一 阿姆斯特丹 列克星敦 和 麦迪逊 如果用户没有输入这些字符串之一 则应反复提示他们 直到他们输入为止 当我输入一个应该可接受的字符串 例如 列克星敦 时 我仍然收到 请输入有效的城市 谁能告诉我当我否定其中
  • 如何区分泛型中的MethodBase

    我有一个基于的缓存 Dictionary
  • 从 Spotify 应用程序内访问 Spotify 元数据 API?

    我想从 Spotify 应用程序中运行 Spotify 搜索 查找某个艺术家的曲目 我没有该艺术家的 Spotify URI 只有名称 我没有在 App API 中找到运行搜索的功能 另一种选择是与ws spotify com访问 Spot
  • 将列表写入 csv 文件而不在 python 中循环

    我有一个列表列表 我需要将其写入 csv 文件 mylist Siddharth Bangalore email protected Rahul Bangalore email protected and so on 该列表通常大约有 20
  • AWS CFN 错误“参数 groupName 不能与参数子网一起使用”

    使用以下 yaml 时出现错误 我检查了代码 但我不认为有任何问题 我的结构计划有一个带有 2 个公有子网和 2 个私有子网的 VPC 一个Web服务器实例将放置在公共子网2中 我认为该问题可能与实例创建有关 因为该错误是在实例创建过程中出