AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

KeyPair

An EC2 Key Pair.

Import

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

Or use the module namespace:

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

Properties

Configuration passed to the constructor as KeyPairProps.

formatOptional
KeyPairFormat

The format of the key pair.

Default: PEM

keyPairNameOptional
string

A unique name for the key pair.

Default: A generated name

publicKeyMaterialOptional
string

The public key material. If this is provided the key is considered "imported". For imported keys, it is assumed that you already have the private key material so the private key material will not be returned or stored in AWS Systems Manager Parameter Store.

Default: a public and private key will be generated

typeOptional
KeyPairType

The type of key pair.

Default: RSA (ignored if keyMaterial is provided)

4 properties inherited from ResourceProps
accountOptionalinherited from ResourceProps
string

The AWS account ID this resource belongs to.

Default: - the resource is in the same account as the stack it belongs to

environmentFromArnOptionalinherited from ResourceProps
string

ARN to deduce region and account from. The ARN is parsed and the account and region are taken from the ARN. This should be used for imported resources. Cannot be supplied together with either `account` or `region`.

Default: - take environment from `account`, `region` parameters, or use Stack environment.

physicalNameOptionalinherited from ResourceProps
string

The value passed in by users to the physical name prop of the resource. - `undefined` implies that a physical name will be allocated by CloudFormation during deployment. - a concrete value implies a specific physical name - `PhysicalName.GENERATE_IF_NEEDED` is a marker that indicates that a physical will only be generated by the CDK if it is needed for cross-environment references. Otherwise, it will be allocated by CloudFormation.

Default: - The physical name will be allocated by CloudFormation at deployment time

regionOptionalinherited from ResourceProps
string

The AWS region this resource belongs to.

Default: - the resource is in the same region as the stack it belongs to

Get the Amazon EC2 Cheat Sheet

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

Download Free Infographic