gpt4 book ai didi

aws-cloudformation - Cloud Formation 模板在创建实例时出现无效的 KeyName 错误。如何修复该问题?

转载 作者:行者123 更新时间:2023-12-03 07:30:15 24 4
gpt4 key购买 nike

error template

当我部署已创建安全组和 key 对的实例时。

我收到错误,因为遇到了不受支持的属性键名。即使我更改了引用并设置了静态值,但仍然存在同样的问题。

我尝试了多次,但都是同样的问题。即使具有静态或引用值(value)。

我的模板如下所示:

---
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
SecurityGroupDescription:
Description: Security Group Descrption
Type: String
SecurtyGroupPort:
Description: Port group to be entered say with max and min values
Type: Number # optional
MinValue: 1150
MaxValue: 65535
InstanceType:
Description: ec2 instance Type
Type: String # optional
Default: t2.small # optional
AllowedValues:
- t1.micro
- t2.nano
- t2.micro
- t2.small
ConstraintDescription: must be a valid EC2 type allowed by your project
DBPwd:
NoEcho: true
Description: database password
Type: String
KeyName:
Description: Name of the keypair to connect instance
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: must be a valid keypair name
SecurityGroupIngressCIDR:
Description: IP range to allow for ec2
Type: String
MinLength: '9'
MaxLength: '18'
Default: 0.0.0.0/0
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
ConstraintDescription: must be a valid CIDR range
MyVPC:
Description: vpc to create instance in
Type: AWS::EC2::VPC::Id
MySubnetIDs:
Description: subnet ids list
Type: "List<AWS::EC2::Subnet::Id>"
DBSubnetIpBlocks:
Description: "comma separated ip addresses CIDR blocks"
Type: CommaDelimitedList
Default: "172.31.120.0/20,172.31.160.0/20,172.31.210.0/20"
Resources:
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceType
Keyname: !Ref KeyName
ImageId: ami-0742b4e673072066f
SubnetId: !Ref DbSubnet1
MySecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Ref SecurityGroupDescription
SecurityGroupIngress:
- CidrIp: !Ref SecurityGroupIngressCIDR
FromPort: !Ref SecurtyGroupPort
ToPort: !Ref SecurtyGroupPort
IpProtocol: tcp
VpcId: !Ref MyVPC
DbSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref MyVPC
CidrBlock: !Select [0, !Ref DBSubnetIpBlocks]
DbSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref MyVPC
CidrBlock: !Select [1, !Ref DBSubnetIpBlocks]
DbSubnet3:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref MyVPC
CidrBlock: !Select [2, !Ref DBSubnetIpBlocks]

最佳答案

它是资源 MyEC2Instance 中的 KeyName,而不是 Keyname(区分大小写)。

请参阅文档 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-keyname

关于aws-cloudformation - Cloud Formation 模板在创建实例时出现无效的 KeyName 错误。如何修复该问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73502730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com