Amazon cloudformation CloudFormation中的属性DeviceIndex不能为空
我对云的形成非常陌生,并试图掌握它。作为学习过程的一部分,我正在尝试构建一个模板,用于创建一个VPC、一个子网和部署一个面向公众的实例。下面是我在CF设计窗口中完成的代码。虽然我的代码只在构建时进行验证,但我得到的错误如下-Amazon cloudformation CloudFormation中的属性DeviceIndex不能为空,amazon-cloudformation,Amazon Cloudformation,我对云的形成非常陌生,并试图掌握它。作为学习过程的一部分,我正在尝试构建一个模板,用于创建一个VPC、一个子网和部署一个面向公众的实例。下面是我在CF设计窗口中完成的代码。虽然我的代码只在构建时进行验证,但我得到的错误如下- CREATE_FAILED AWS::EC2::Instance AR3Web Property DeviceIndex cannot be empty. ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack Int
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
您看到该消息是因为您的网络接口数组中有一个输入错误。你有:
NetworkInterfaces:
- GroupSet:
- !Ref AR3WebSG
AssociatePublicIpAddress: 'true'
DeviceIndex: '0'
DeleteOnTermination: 'true'
- SubnetId: !Ref PublicSubnet1
SubnetId旁边的连字符似乎是一个输入错误,但在YAML中,它表示网络接口数组中的一个新元素。因此,虽然第一个元素有DeviceIndex:0,但第二个元素没有DeviceIndex,这就是您接收该消息的原因
将其更改为:
NetworkInterfaces:
- GroupSet:
- !Ref AR3WebSG
AssociatePublicIpAddress: 'true'
DeviceIndex: '0'
DeleteOnTermination: 'true'
SubnetId: !Ref PublicSubnet1
非常感谢,亚历克斯。你真有一双锐利的眼睛!这解决了问题,堆栈成功完成!