amazon-web-services - VPC 错误:模板的资源块中未解决的资源依赖项 [VPC]
问题描述
我正在使用 cloudformation 创建一个 vpc,但运行它时显示错误。我已经创建了带有 Internet 网关的 vpc 和 2 个子网,一个是公共的,另一个是私有的,但是当我将 yaml 文件上传到 cloudformation 时,它显示以下错误我的 yml 文件:
---
Description: An AWS VPC with two subnets.
AWSTemplateFormatVersion: 2010-09-09
Resources:
myVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 11.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
InternetGateway:
Type: AWS::EC2::InternetGateway
VPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref myVPC
InternetGatewayId: !Ref InternetGateway
SubnetA:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-2a
VpcId: !Ref myVPC
CidrBlock: 11.0.1.0/24
MapPublicIpOnLaunch: true
SubnetB:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-2a
VpcId: !Ref myVPC
CidrBlock: 11.0.0.0/24
MapPublicIpOnLaunch: false
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref myVPC
InternetRoute:
Type: AWS::EC2::Route
DependsOn: VPCGatewayAttachment
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
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "Internet Group"
GroupDescription: "SSH traffic in, all traffic out."
VpcId: !Ref myVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: "22"
ToPort: "22"
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http to client host
VpcId: !Ref myVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
RDSSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http to client host
VpcId: !Ref myVPC
RDSSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref RDSSecurityGroup
IpProtocol: tcp
FromPort: 3306
ToPort: 3306
SourceSecurityGroupId: !Ref InstanceSecurityGroup
myDBSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: "description"
SubnetIds:
- !Ref SubnetB
wahajwebserver:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0bdcc6c05dec346bf
InstanceType: t2.micro
KeyName: wahaj(webserver)
SubnetId:
Ref: SubnetA
SecurityGroupIds: [!Ref InstanceSecurityGroup]
wahajdbRDS:
Type: AWS::RDS::DBInstance
Properties:
AllocatedStorage: 20
AvailabilityZone: us-east-2c
DBInstanceClass: db.t2.micro
DBInstanceIdentifier: wahajwebserver
DBName: wahajdb
DBSubnetGroupName: !Ref myDBSubnetGroup
DeleteAutomatedBackups: true
Engine: MySQL
MasterUsername: wahajdb
MasterUserPassword: wahajdb
VPCSecurityGroups: [!Ref RDSSecurityGroup]
我曾尝试在 cli 中使用 validate 函数,但错误同样无法找出错误。
解决方案
您对的引用!Ref VPC
应该是!Ref myVPC
. 期望存在名为的!Ref VPC
参数或资源VPC
,您已将 VPC 资源命名为myVPC
。
---
Description: An AWS VPC with two subnets.
AWSTemplateFormatVersion: 2010-09-09
Resources:
myVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 11.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
InternetGateway:
Type: AWS::EC2::InternetGateway
VPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref myVPC
InternetGatewayId: !Ref InternetGateway
SubnetA:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-2a
VpcId: !Ref myVPC
CidrBlock: 11.0.1.0/24
MapPublicIpOnLaunch: true
SubnetB:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-2a
VpcId: !Ref myVPC
CidrBlock: 11.0.0.0/24
MapPublicIpOnLaunch: false
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref myVPC
InternetRoute:
Type: AWS::EC2::Route
DependsOn: VPCGatewayAttachment
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
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "Internet Group"
GroupDescription: "SSH traffic in, all traffic out."
VpcId: !Ref myVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: "22"
ToPort: "22"
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
推荐阅读
- excel - 如何将每个单独的 excel 行导出到自己的单独 csv 文件?
- c# - 动态生成列时,如何修复 DataGrid 中缺少的行显示?
- php - FosUserBundle 模拟外部
- css - 为什么 CSS background-image url 不显示我的图像,尽管链接和路径是正确的?
- windows - 是否可以使用 AWS 运行普通的 Windows 10 机器?
- php - 使用 UPDATE 不会将图像加载到我的数据库
- php - Laravel 5.4 Query Builder 数组到字符串的转换
- php - PHP:从 WSDL 访问另一个数组中的对象内的数组
- php - How to fix Yii2 Contact Widget Problem on View Pages
- docker - 如何在没有互联网连接的情况下启动 Docker?