简体   繁体   English

AWS:使用带有现有密钥对的Cloud Formation部署堆栈

[英]AWS: Deploying a stack using Cloud Formation with an existing Key Pair

I started using AWS a couple days ago. 我几天前开始使用AWS。

I would like to use the Cloud Formation service to deploy a stack, then be able to SSH into the deployed instance. 我想使用Cloud Formation服务来部署堆栈,然后能够SSH到已部署的实例中。 While creating the template, I did not see an option to include a key pair. 创建模板时,我没有看到包含密钥对的选项。

According to this , I need to have a key pair from the start. 根据这个 ,我需要从一开始就密钥对。

How can I deploy a stack with a key pair, so that I may SSH into it once it has been deployed? 如何部署带有密钥对的堆栈,以便在部署后可以通过SSH对其进行SSH?

I also tried altering the template in a text file by adding a KeyName section under parameters: 我还尝试通过在参数下添加KeyName部分来更改文本文件中的模板:

"Parameters" : {
"AccessControl" : {
  "Description" : " The IP address range that can be used to access the CloudFormer tool. NOTE: We highly recommend that you specify a customized address range to lock down the tool.",
  "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 IP CIDR range of the form x.x.x.x/x."
}  

"KeyName" : {
  "Description" : " Name of an existing EC2 KeyPair to enable SSH access to the instances",
  "Type": "String",
  "MinLength": "1",
  "MaxLength": "64",
  "AllowedPattern": "[-_ a-zA-Z0-9]*",
  "ConstraintDescription": "Can contain only alphanumeric characters, spaces, dashes, and underscores."
}

This results in the following error: "Template validation error: Template format error: JSON not well-formed." 这将导致以下错误:“模板验证错误:模板格式错误:JSON格式不正确。”

I want to be able to remote into both Linux and Windows instances. 我希望能够远程访问Linux和Windows实例。

you can use "Default" to specify a default key name 您可以使用“默认”指定默认密钥名称

    "KeyPair" : {
        "Type" : "String",
        "Default" : "MyKeyName",
        "Description" : "Enter a keypair for this instance"
    }

then in "Properties" 然后在“属性”中

    "Properties": {
        "KeyName": { "Ref": "KeyPair" },

You need to create the key, and then use the name of the key as a parameter to your Cloud Formation script. 您需要创建密钥,然后将密钥的名称用作Cloud Formation脚本的参数。

The JSON error is probably due to a missing comma after the closing } of the AccessControl property value. JSON错误可能是由于AccessControl属性值的}结束后缺少逗号引起的。

There is a JSON validator at http://jsonlint.com/ that will highlight these types of formatting errors. http://jsonlint.com/上有一个JSON验证器,它将突出显示这些类型的格式错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM