2

I started using AWS a couple days ago.

I would like to use the Cloud Formation service to deploy a stack, then be able to SSH into the deployed instance. 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?

I also tried altering the template in a text file by adding a KeyName section under parameters:

"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."

I want to be able to remote into both Linux and Windows instances.

Community
  • 1
  • 1
Hyatt
  • 23
  • 1
  • 3

2 Answers2

2

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" },
Paul S
  • 1,424
  • 1
  • 14
  • 12
0

You need to create the key, and then use the name of the key as a parameter to your Cloud Formation script.

The JSON error is probably due to a missing comma after the closing } of the AccessControl property value.

There is a JSON validator at http://jsonlint.com/ that will highlight these types of formatting errors.

jeremcc
  • 8,633
  • 11
  • 45
  • 55
chris
  • 36,094
  • 53
  • 157
  • 237