我正在使用云形成来创建VPC。它在创建子网时失败了。我查了一下,我相信子网是有效的。虽然我的网络知识有点缺乏。
这是我得到的错误:
00:46:49 UTC-0400 CREATE_FAILED AWS::EC2::Subnet SubnetA The CIDR '172.16.64.0/16' is invalid.
00:46:49 UTC-0400 CREATE_IN_PROGRESS AWS :: EC2 :: RouteTable RouteTable资源创建已启动 00:46:49 UTC-0400 CREATE_FAILED AWS :: EC2 :: Subnet SubnetB CIDR'197.16.128.0/16'无效。
这是我正在尝试使用的模板:
---
AWSTemplateFormatVersion: 2010-09-09
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 172.16.0.0/18
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
Tags:
- Key: Name
Value: JF-Staging-VPC
InternetGateway:
Type: AWS::EC2::InternetGateway
VPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
SubnetA:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-1a
VpcId: !Ref VPC
CidrBlock: 172.16.64.0/16
MapPublicIpOnLaunch: False
SubnetB:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-1b
VpcId: !Ref VPC
CidrBlock: 197.16.128.0/16
MapPublicIpOnLaunch: False
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
InternetRoute:
Type: AWS::EC2::Route
DependsOn: InternetGateway
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
RouteTableId: !Ref RouteTable
SubnetARouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTable
SubnetId: !Ref SubnetA
SubnetBRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTable
SubnetId: !Ref SubnetB
SecurityGroupSSH:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "SSH Group"
GroupDescription: "SSH traffic in, all traffic out."
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
SecurityGroupWeb:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "Web Group"
GroupDescription: "Web traffic in, all traffic out."
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
Metadata:
VPC:
Description: "Creating the JF Staging VPC"
InternetGateway:
Description: "Creating an Internet Gateway"
有人能让我知道我哪里出错了,以及如何纠正这个问题?
答案 0 :(得分:2)
根据错误消息,您的IP地址(CIDR)范围无效。
设置以下CIDR范围:
这些子网范围都不是VPC范围的一部分。所有子网范围必须在VPC指定的范围内。实际上,两个子网都比
例如,这里的范围可以正常工作:
如果您不了解CIDR范围,请参阅:Understanding IP Addresses, Subnets, and CIDR Notation for Networking
答案 1 :(得分:1)
问题在于197.16.128.0/16,这是一个公共IP地址,无法分配给VPC或子网。
我认为你真的打算使用这个地址:
172.16.128.0/16
[编辑]
将您的VPC更改为172.16.0.0/16 然后更改每个子网以使用/ 16的一部分,例如/ 24 示例:
172.16.0.0/24
172.16.1.0/24
172.16.2.0/24
等
您当前实现的问题是您的VPC是/ 18,它小于您尝试创建的子网/ 16。你想要反向,/ 16为VPC和/ 24或任何小于/ 16的子网。