# KeyPairProps

The properties of a Key Pair.

Extends: KeyPairProps
Extends: ResourceProps
Used as props by: KeyPair

- Source: [`aws-ec2/lib/key-pair.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-ec2/lib/key-pair.ts#L48)
- Type last changed: v2.116.0 · 22 Dec 2023

## Example

```ts
declare const vpc: ec2.Vpc;
declare const instanceType: ec2.InstanceType;

const keyPair = new ec2.KeyPair(this, 'KeyPair', {
  type: ec2.KeyPairType.ED25519,
  format: ec2.KeyPairFormat.PEM,
});
const instance = new ec2.Instance(this, 'Instance', {
  vpc,
  instanceType,
  machineImage: ec2.MachineImage.latestAmazonLinux2023(),
  // Use the custom key pair
  keyPair,
});
```

## Properties

- `account`: string — The AWS account ID this resource belongs to.

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

- `environmentFromArn`: string — ARN to deduce region and account from.

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

  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`.

- `format`: [KeyPairFormat](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.KeyPairFormat.html) = PEM — The format of the key pair.

- `keyPairName`: string — A unique name for the key pair.

  **Default:** A generated name

- `physicalName`: string — The value passed in by users to the physical name prop of the resource.

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

  - `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.

- `publicKeyMaterial`: string — The public key material.

  **Default:** a public and private key will be generated

  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.

- `region`: string — The AWS region this resource belongs to.

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

- `type`: [KeyPairType](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.KeyPairType.html) — The type of key pair.

  **Default:** RSA (ignored if keyMaterial is provided)
