我对CloudFormation还是陌生的,并试图抓住它。作为学习过程的一部分,我试图构建一个模板,用于创建VPC,一个子网并部署面向公众的实例。下面是我在CF设计窗口中完成的代码。虽然我的代码可以验证,但是在构建时间上却出现类似-
的错误CREATE_FAILED AWS::EC2::Instance AR3Web Property DeviceIndex cannot be empty.
ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack Intro The following resource(s) failed to create:[IgwAttachment, AR3Web]. . Rollback requested by user.
我在代码中设置DeviceIndex:'0'。有人可以帮我了解我要去哪里了吗?
谢谢您的帮助。
我的代码-
---
AWSTemplateFormatVersion: 2010-09-09
Description: Test Stack
Resources:
AR3VPC:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
InstanceTenancy: default
Tags:
- Key: Name
Value: AR3VPC
Metadata:
'AWS::CloudFormation::Designer':
id: baa1b4d4-07ea-4095-b4a4-4925e7c68052
PublicSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref AR3VPC
CidrBlock: 10.0.1.0/24
MapPublicIpOnLaunch: 'true'
AvailabilityZone: us-east-1a
Metadata:
'AWS::CloudFormation::Designer':
id: 24f10588-e12e-45bf-a270-c844afa4d9a7
AR3Web:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: 'ami-a4c7edb2'
InstanceType: 't2.micro'
KeyName: virginiakp
NetworkInterfaces:
- GroupSet:
- !Ref AR3WebSG
AssociatePublicIpAddress: 'true'
DeviceIndex: '0'
DeleteOnTermination: 'true'
- SubnetId: !Ref PublicSubnet1
Metadata:
'AWS::CloudFormation::Designer':
id: 6080a1d9-2670-48db-abf8-a7a3ac597f2e
AR3WebSG:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Allow HTTP access
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
VpcId: !Ref AR3VPC
Tags:
- Key: Name
Value: AR3WebSecurityGroup
Metadata:
'AWS::CloudFormation::Designer':
id: 2870d531-f538-4bee-8a03-393012432b71
AR3IGW:
Type: 'AWS::EC2::InternetGateway'
Properties:
Tags:
- Key: Name
Value: AR3 IGW
Metadata:
'AWS::CloudFormation::Designer':
id: c2557116-9cd5-4826-9932-656e90b271a1
AR3Rt:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref AR3VPC
Metadata:
'AWS::CloudFormation::Designer':
id: e9f2dfcc-e65b-49c5-8a21-66dd3b012549
PubRt:
Type: 'AWS::EC2::Route'
DependsOn: IgwAttachment
Properties:
RouteTableId: !Ref AR3Rt
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref AR3IGW
Metadata:
'AWS::CloudFormation::Designer':
id: 37bac7d1-69ee-4c1c-9a8d-8940e586b590
IgwAttachment:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
InternetGatewayId: !Ref AR3IGW
VpcId: !Ref AR3VPC
Metadata:
'AWS::CloudFormation::Designer':
id: 72d68293-8163-4372-a771-1f4a4062d6dd
PublicSubnetRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref PublicSubnet1
RouteTableId: !Ref AR3Rt
Metadata:
'AWS::CloudFormation::Designer':
id: 7e429e8b-2fb5-49de-a383-60ec910ed505
答案 0 :(得分:1)
您正在看到该消息,因为网络接口阵列中有一个错字。你有:
NetworkInterfaces:
- GroupSet:
- !Ref AR3WebSG
AssociatePublicIpAddress: 'true'
DeviceIndex: '0'
DeleteOnTermination: 'true'
- SubnetId: !Ref PublicSubnet1
SubnetId旁边的连字符似乎是一个错字,但是在YAML中,它表示NetworkInterfaces数组中的一个新元素。因此,尽管第一个元素的DeviceIndex为0,第二个元素的DeviceIndex没有,这就是为什么您收到该消息的原因。
将其更改为:
NetworkInterfaces:
- GroupSet:
- !Ref AR3WebSG
AssociatePublicIpAddress: 'true'
DeviceIndex: '0'
DeleteOnTermination: 'true'
SubnetId: !Ref PublicSubnet1