KeyPairProps

class aws_cdk.aws_ec2.KeyPairProps(*, account=None, environment_from_arn=None, physical_name=None, region=None, format=None, key_pair_name=None, public_key_material=None, type=None)

Bases: ResourceProps

The properties of a Key Pair.

Parameters:
  • account (Optional[str]) – The AWS account ID this resource belongs to. Default: - the resource is in the same account as the stack it belongs to

  • environment_from_arn (Optional[str]) – 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.

  • physical_name (Optional[str]) – 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

  • region (Optional[str]) – The AWS region this resource belongs to. Default: - the resource is in the same region as the stack it belongs to

  • format (Optional[KeyPairFormat]) – The format of the key pair. Default: PEM

  • key_pair_name (Optional[str]) – A unique name for the key pair. Default: A generated name

  • public_key_material (Optional[str]) – 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

  • type (Optional[KeyPairType]) – The type of key pair. Default: RSA (ignored if keyMaterial is provided)

ExampleMetadata:

infused

Example:

# vpc: ec2.Vpc
# instance_type: ec2.InstanceType


key_pair = ec2.KeyPair(self, "KeyPair",
    type=ec2.KeyPairType.ED25519,
    format=ec2.KeyPairFormat.PEM
)
instance = ec2.Instance(self, "Instance",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=ec2.MachineImage.latest_amazon_linux2023(),
    # Use the custom key pair
    key_pair=key_pair
)

Attributes

account

The AWS account ID this resource belongs to.

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

environment_from_arn

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.

format

The format of the key pair.

Default:

PEM

key_pair_name

A unique name for the key pair.

Default:

A generated name

physical_name

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

public_key_material

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

region

The AWS region this resource belongs to.

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

type

The type of key pair.

Default:

RSA (ignored if keyMaterial is provided)