CloudFormation:如何取得給定區域中的金鑰對列表

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

如何使用 CloudFormation 檢索部署範本的區域中的金鑰對清單?

答案1

而不是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

查看AWS 特定的參數類型取得您可以使用的參數類型的完整清單。有些填入可用值(例如 SSH 金鑰、VPC ID、子網路 ID 等),有些則不填入(例如 AMI 映像 ID)。

希望有幫助:)

相關內容