CloudFormation 模板不选择密钥对
CloudFormation Template doesnt pick KeyPair
我使用 Cloud Formation Template (CFT)
:
成功创建了以下四个资源
- VPC
- 子网
- 互联网网关
- 附加网关
现在,我正在尝试使用 EC2 实例创建一个安全组,这是代码。
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http and ssh to client host
VpcId:
Ref: InsuranceVPC
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
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: "ami-08706cb5f68222d09"
KeyName:
Ref: "DevOpsAutomation"
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- Ref: "InsuranceSecurityGroup"
SubnetId:
Ref: "InsuranceSubnet"
但是,当我在(CFT,如上所示,代码)中使用密钥参数时,我的密钥出现在同一资源区域中,我的 CFT 堆栈失败并出现以下错误:
Template format error: Unresolved resource dependencies [DevOpsAutomation] in the Resources block of the template
note: DevOpsAutomation is my keyname
我验证的步骤:
- CFT模板资源和key在同一区域
- 已删除和新创建的密钥对
- 尝试使用不同的密钥对
- 我在任何地方都看不到将密钥与 CFT 堆栈一起导入以便我的 EC2 实例可以使用它的选项。
- 即使在创建堆栈时,密钥也不会出现在堆栈的
parameter
部分中 (在 keypair
部分可见)。
我的问题是,我应该如何使用我的 AWS 账户中存在的密钥对创建 EC2 实例(作为 CFT 的一部分)?
去掉键名前面的Ref
。 Ref
用于引用已定义为 CloudFormation 模板一部分的其他资源。如果密钥对已经存在,您可以直接使用密钥名称。
KeyName: "DevOpsAutomation"
我在这里复制了一个例子
AWSTemplateFormatVersion: '2010-09-09'
Description: >
AWS CloudFormation template to create Jenkins server
Parameters:
KeyName:
Type: AWS::EC2::KeyPair::KeyName
Default: ritefit-keypair
Resources:
JenkinsEC2Instance:
Type: AWS::EC2::Instance
Properties:
KeyName: !Ref KeyName
向我们展示更多定义了 KeyName 的内容,以便我们可以帮助您解决问题所在
我使用 Cloud Formation Template (CFT)
:
- VPC
- 子网
- 互联网网关
- 附加网关
现在,我正在尝试使用 EC2 实例创建一个安全组,这是代码。
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http and ssh to client host
VpcId:
Ref: InsuranceVPC
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
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: "ami-08706cb5f68222d09"
KeyName:
Ref: "DevOpsAutomation"
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- Ref: "InsuranceSecurityGroup"
SubnetId:
Ref: "InsuranceSubnet"
但是,当我在(CFT,如上所示,代码)中使用密钥参数时,我的密钥出现在同一资源区域中,我的 CFT 堆栈失败并出现以下错误:
Template format error: Unresolved resource dependencies [DevOpsAutomation] in the Resources block of the template
note: DevOpsAutomation is my keyname
我验证的步骤:
- CFT模板资源和key在同一区域
- 已删除和新创建的密钥对
- 尝试使用不同的密钥对
- 我在任何地方都看不到将密钥与 CFT 堆栈一起导入以便我的 EC2 实例可以使用它的选项。
- 即使在创建堆栈时,密钥也不会出现在堆栈的
parameter
部分中 (在keypair
部分可见)。
我的问题是,我应该如何使用我的 AWS 账户中存在的密钥对创建 EC2 实例(作为 CFT 的一部分)?
去掉键名前面的Ref
。 Ref
用于引用已定义为 CloudFormation 模板一部分的其他资源。如果密钥对已经存在,您可以直接使用密钥名称。
KeyName: "DevOpsAutomation"
我在这里复制了一个例子
AWSTemplateFormatVersion: '2010-09-09'
Description: >
AWS CloudFormation template to create Jenkins server
Parameters:
KeyName:
Type: AWS::EC2::KeyPair::KeyName
Default: ritefit-keypair
Resources:
JenkinsEC2Instance:
Type: AWS::EC2::Instance
Properties:
KeyName: !Ref KeyName
向我们展示更多定义了 KeyName 的内容,以便我们可以帮助您解决问题所在