CloudFormation:如何获取给定区域中的密钥对列表

Mar*_*ani 3 amazon-cloudformation

我有一个非常简单的 CF 模板,用于创建 EC2 实例。密钥对被指定为参数。我希望自动填充可能的密钥对列表。

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
Run Code Online (Sandbox Code Playgroud)

如何使用 CloudFormation 检索部署模板的区域中的密钥对列表?

MLu*_*MLu 5

而不是Type: String使用Type: AWS::EC2::KeyPair::KeyName,它应该为您填充列表。

这应该做:

Parameters:
  SSHKey:
    Type: AWS::EC2::KeyPair::KeyName
    Description: name of the key pair to ssh into the instance
Run Code Online (Sandbox Code Playgroud)

查看AWS 特定的参数类型以获取您可以使用的参数类型的完整列表。有些填充可用值(例如 SSH 密钥、VPC ID、子网 ID 等),有些则不填充(例如 AMI 映像 ID)。

希望有帮助:)