AWS CloudFormation 能否创建 KeyPair 以便随后在启动实例时使用?

Pet*_*nce 9 keys amazon-web-services amazon-cloudformation

我想使用作为 CloudFormation 一部分创建的密钥对启动我的堆栈。

那可能吗?

....
"Resources": {
    "ReverseProxyKeyPair": {
        "Type": "AWS::EC2::KeyPair",
        "Properties": {
            "KeyName": "reverse_proxy"
        }
    },
....
Run Code Online (Sandbox Code Playgroud)

是一个猜测,但没有奏效。我还没有找到 CloudFormation 的架构来说明这是不可能的。

大多数示例都假设已经创建了 KeyPair - 我假设是因为在创建时只有一次下载它的机会。但我想动态创建一个,然后将其用作输出并将其转储到 S3 中(比如说)。

或者,这是一个愚蠢的想法吗?

Dan*_*son 7

这是 CloudFormation 支持的所有资源类型的列表;未列出密钥对:

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


neu*_*uen 1

根据文档,(现在)可以使用 cloudformation 创建密钥对:

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

要创建新的密钥对,请省略 PublicKeyMaterial 属性。

当您创建新密钥对时,私钥将使用具有以下名称的参数保存到 AWS Systems Manager Parameter Store:/ec2/keypair/{key_pair_id}。有关检索私钥和所需权限的更多信息,请参阅 Amazon EC2 用户指南中的使用 AWS CloudFormation 创建密钥对。

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