AWS Fundamentals Logo
AWS Fundamentals
L1 ConstructAWS::EC2::KeyPair

CfnKeyPair

Specifies a key pair for use with an Amazon Elastic Compute Cloud instance as follows:. - To import an existing key pair, include the `PublicKeyMaterial` property. - To create a new key pair, omit the `PublicKeyMaterial` property. When you import an existing key pair, you specify the public key material for the key. We assume that you have the private key material for the key. AWS CloudFormation does not create or return the private key material when you import a key pair. 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 CloudFormation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html#create-key-pair-cloudformation) in the *Amazon EC2 User Guide* . When CloudFormation deletes a key pair that was created or imported by a stack, it also deletes the parameter that was used to store the private key material in Parameter Store.

Import

import { CfnKeyPair } from 'aws-cdk-lib/aws-ec2';

Or use the module namespace:

import * as ec2 from 'aws-cdk-lib/aws-ec2';
// ec2.CfnKeyPair

Properties

Configuration passed to the constructor as CfnKeyPairProps.

keyNameRequired
string

A unique name for the key pair. Constraints: Up to 255 ASCII characters

keyFormatOptional
string

The format of the key pair. Default: `pem`

Default: - "pem"

keyTypeOptional
string

The type of key pair. Note that ED25519 keys are not supported for Windows instances. If the `PublicKeyMaterial` property is specified, the `KeyType` property is ignored, and the key type is inferred from the `PublicKeyMaterial` value. Default: `rsa`

Default: - "rsa"

publicKeyMaterialOptional
string

The public key material. The `PublicKeyMaterial` property is used to import a key pair. If this property is not specified, then a new key pair will be created.

tagsOptional
CfnTag[]

The tags to apply to the key pair.

CloudFormation Resource

This L1 construct maps directly to the following CloudFormation resource type.

Get the Amazon EC2 Cheat Sheet

Everything you need to know about Amazon EC2 on one page. HD quality, print-friendly.

Download Free Infographic