rp1*_*409 6 aws-cloudformation
我对 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.
Run Code Online (Sandbox Code Playgroud)
我在代码中设置 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
Run Code Online (Sandbox Code Playgroud)
您看到该消息是因为您的网络接口数组中有拼写错误。你有:
NetworkInterfaces:
- GroupSet:
- !Ref AR3WebSG
AssociatePublicIpAddress: 'true'
DeviceIndex: '0'
DeleteOnTermination: 'true'
- SubnetId: !Ref PublicSubnet1
Run Code Online (Sandbox Code Playgroud)
SubnetId 旁边的连字符似乎是一个拼写错误,但在 YAML 中,它表示 NetworkInterfaces 数组中的一个新元素。因此,虽然第一个元素具有 DeviceIndex: 0,但第二个元素没有 DeviceIndex,这就是您收到该消息的原因。
将其更改为:
NetworkInterfaces:
- GroupSet:
- !Ref AR3WebSG
AssociatePublicIpAddress: 'true'
DeviceIndex: '0'
DeleteOnTermination: 'true'
SubnetId: !Ref PublicSubnet1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5362 次 |
| 最近记录: |