amazon-web-services - 将 EC2 实例放置在特定子网中时出现 CloudFormation 模板错误

标签 amazon-web-services yaml aws-cloudformation

正在处理 CF 示例模板,并尝试将 EC2 实例放入根据同一模板创建的子网中。当按原样执行操作时,我收到此错误:

The parameter groupName cannot be used with the parameter subnet

这是模板的子集:

Resources:
VPC:
  Type: AWS::EC2::VPC
  Properties:
      CidrBlock: 172.34.0.0/16                                  
      EnableDnsHostnames: False
      Tags:
Subnet1:
  Type: AWS::EC2::Subnet
  Properties:
    AvailabilityZone: us-west-1a
    CidrBlock: 172.34.0.0/24
    VpcId: 
      Ref: VPC
    MapPublicIpOnLaunch: False
WebServer1:
  Type: AWS::EC2::Instance
  Properties:
    ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", AMI]
    InstanceType: t2.micro                                   
    SubnetId:
      Ref: Subnet1
    SecurityGroups: 
      - Ref: ServerSecurityGroup
    Tags:
      - Key: "Name"
        Value: "Tyler-Cloudformation"

创建 WebServer1 时如何引用 Subnet 1 并将其放置在该子网中?我在这里缺少什么?预先感谢!

最佳答案

该错误可能是因为您使用的是 SecurityGroups 而不是 SecurityGroupIds 。前一个参数仅适用于默认VPC,非默认VPC则必须使用后者。

因此,您应该拥有:

,而不是 SecurityGroups
      SecurityGroupIds: 
        - !GetAtt ServerSecurityGroup.GroupId

关于amazon-web-services - 将 EC2 实例放置在特定子网中时出现 CloudFormation 模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65242427/

相关文章:

amazon-web-services - Ansible EC2 动态 list - 包含连字符的标签

yaml - 如何根据 IAM 角色 CloudFormation 模板中的参数提供不同的条件

amazon-web-services - cdk/cloudformation 如何了解哪个子网是私有(private)子网还是公共(public)子网?

aws-cloudformation - 使用 Lambda 函数自动创建的角色的 ARN

amazon-web-services - https SSL AWS ELB 单实例

amazon-web-services - AWS Step Functions 未捕获 States.Runtime 错误

ssl - 我网站的 AWS 负载均衡器和 ssl 证书

java - 使用 SnakeYaml 向节点添加注释

java - 创建配置.yml 文件

amazon-web-services - 在 Cloudformation 上更新堆栈时 AWS key 发生轮换