3

I have a very simple CF template that creates an EC2 instance. The key pair is specified as a parameter. I would like the list of possible key pairs to be populated automatically.

Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      AvailabilityZone: eu-west-2a
      ImageId: ami-0e80a462ede03e653
      InstanceType: t3.nano
      KeyName: !Ref SSHKey

Parameters:
  SSHKey:
    Type: String
    Description: name of the key pair to ssh into the instance
    AllowedValues:
      # populate automatically

How can I retrieve with CloudFormation the list of key pairs in the region where the template is being deployed?

1 Answer 1

5

Instead of Type: String use Type: AWS::EC2::KeyPair::KeyName and it should populate the list for you.

This should do:

Parameters:
  SSHKey:
    Type: AWS::EC2::KeyPair::KeyName
    Description: name of the key pair to ssh into the instance

Check out AWS-specific parameter types for a complete list of parameter types that you can use. Some populate the available values (like the SSH Keys, VPC IDs, Subnet IDs, etc), some don't (for example the AMI Image IDs).

Hope that helps :)

You must log in to answer this question.

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