10

I would like to launch my stack using a keypair that is created as part of the CloudFormation.

Is that possible?

....
"Resources": {
    "ReverseProxyKeyPair": {
        "Type": "AWS::EC2::KeyPair",
        "Properties": {
            "KeyName": "reverse_proxy"
        }
    },
....

was a guess, but hasn't worked. I haven't tracked down a schema for CloudFormation to say this isn't possible.

Most of the examples assume a KeyPair has already been created - I assume because there's only one chance to download it, at creation-time. But I'd like to dynamically create one, and then use it as an Output and dump it into S3 (say).

Or, is this a silly idea?

2 Answers 2

1

According to the documentation, it is (now) possible to create a key pair with cloudformation:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-keypair.html

To create a new key pair, omit the PublicKeyMaterial property.

When you create a new key pair, the private key is saved to AWS Systems Manager Parameter Store, using a parameter with the following name: /ec2/keypair/{key_pair_id}. For more information about retrieving private key, and the required permissions, see Create a key pair using AWS CloudFormation in the Amazon EC2 User Guide.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html#create-key-pair-cloudformation

8

This is a list of all the resource types supported by CloudFormation; a key pair isn't listed:

http://docs.amazonwebservices.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html

1
  • KeyPair is listed within Amazon EC2. Just because it is not listed directly on the linked page does NOT mean it isn't supported.
    – neuquen
    Apr 7, 2023 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .