Class KeyPair
An EC2 Key Pair.
Inherited Members
Namespace: Amazon.CDK.AWS.EC2
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class KeyPair : Resource, IKeyPair, IResource, IKeyPairRef, IConstruct, IDependable, IEnvironmentAware
Syntax (vb)
Public Class KeyPair Inherits Resource Implements IKeyPair, IResource, IKeyPairRef, IConstruct, IDependable, IEnvironmentAware
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused
Examples
Vpc vpc;
InstanceType instanceType;
var keyPair = new KeyPair(this, "KeyPair", new KeyPairProps {
Type = KeyPairType.ED25519,
Format = KeyPairFormat.PEM
});
var instance = new Instance(this, "Instance", new InstanceProps {
Vpc = vpc,
InstanceType = instanceType,
MachineImage = MachineImage.LatestAmazonLinux2023(),
// Use the custom key pair
KeyPair = keyPair
});
Synopsis
Constructors
| KeyPair(Construct, string, IKeyPairProps?) | An EC2 Key Pair. |
Properties
| Format | The format of the key pair. |
| HasImportedMaterial | Whether the key material was imported. |
| KeyPairFingerprint | The fingerprint of the key pair. |
| KeyPairId | The unique ID of the key pair. |
| KeyPairName | The unique name of the key pair. |
| KeyPairRef | A reference to a KeyPair resource. |
| PROPERTY_INJECTION_ID | Uniquely identifies this class. |
| PrivateKey | The Systems Manager Parameter Store parameter with the pair's private key material. |
| Type | The type of the key pair. |
Methods
| FromKeyPairAttributes(Construct, string, IKeyPairAttributes) | Imports a key pair with a name and optional type. |
| FromKeyPairName(Construct, string, string) | Imports a key pair based on the name. |
Constructors
KeyPair(Construct, string, IKeyPairProps?)
An EC2 Key Pair.
public KeyPair(Construct scope, string id, IKeyPairProps? props = null)
Parameters
- scope Construct
- id string
- props IKeyPairProps
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused
Examples
Vpc vpc;
InstanceType instanceType;
var keyPair = new KeyPair(this, "KeyPair", new KeyPairProps {
Type = KeyPairType.ED25519,
Format = KeyPairFormat.PEM
});
var instance = new Instance(this, "Instance", new InstanceProps {
Vpc = vpc,
InstanceType = instanceType,
MachineImage = MachineImage.LatestAmazonLinux2023(),
// Use the custom key pair
KeyPair = keyPair
});
Properties
Format
The format of the key pair.
public virtual KeyPairFormat Format { get; }
Property Value
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused
HasImportedMaterial
Whether the key material was imported.
public virtual bool HasImportedMaterial { get; }
Property Value
Remarks
Keys with imported material do not have their private key material stored or returned automatically.
KeyPairFingerprint
The fingerprint of the key pair.
public virtual string KeyPairFingerprint { get; }
Property Value
Remarks
Attribute: true
KeyPairId
The unique ID of the key pair.
public virtual string KeyPairId { get; }
Property Value
Remarks
Attribute: true
KeyPairName
The unique name of the key pair.
public virtual string KeyPairName { get; }
Property Value
Remarks
Attribute: true
KeyPairRef
A reference to a KeyPair resource.
public virtual IKeyPairReference KeyPairRef { get; }
Property Value
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused
PROPERTY_INJECTION_ID
Uniquely identifies this class.
public static string PROPERTY_INJECTION_ID { get; }
Property Value
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused
PrivateKey
The Systems Manager Parameter Store parameter with the pair's private key material.
public virtual IStringParameter PrivateKey { get; }
Property Value
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused
Type
The type of the key pair.
public virtual KeyPairType? Type { get; }
Property Value
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused
Methods
FromKeyPairAttributes(Construct, string, IKeyPairAttributes)
Imports a key pair with a name and optional type.
public static IKeyPair FromKeyPairAttributes(Construct scope, string id, IKeyPairAttributes attrs)
Parameters
- scope Construct
- id string
- attrs IKeyPairAttributes
Returns
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused
FromKeyPairName(Construct, string, string)
Imports a key pair based on the name.
public static IKeyPair FromKeyPairName(Construct scope, string id, string keyPairName)
Parameters
Returns
Remarks
Resource: AWS::EC2::KeyPair
ExampleMetadata: infused