Class CfnKeyPair

java.lang.Object
software.amazon.jsii.JsiiObject
All Implemented Interfaces:
IConstruct, IDependable, IInspectable, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:38.676Z") @Stability(Stable) public class CfnKeyPair extends CfnResource implements IInspectable
A CloudFormation AWS::EC2::KeyPair.

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 AWS CloudFormation in the Amazon EC2 User Guide .

When AWS 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.

Example:

 // The code below shows an example of how to instantiate this type.
 // The values are placeholders you should change.
 import software.amazon.awscdk.services.ec2.*;
 CfnKeyPair cfnKeyPair = CfnKeyPair.Builder.create(this, "MyCfnKeyPair")
         .keyName("keyName")
         // the properties below are optional
         .keyType("keyType")
         .publicKeyMaterial("publicKeyMaterial")
         .tags(List.of(CfnTag.builder()
                 .key("key")
                 .value("value")
                 .build()))
         .build();
 
  • Field Details

    • CFN_RESOURCE_TYPE_NAME

      @Stability(Stable) public static final String CFN_RESOURCE_TYPE_NAME
      The CloudFormation resource type name for this resource class.
  • Constructor Details

    • CfnKeyPair

      protected CfnKeyPair(software.amazon.jsii.JsiiObjectRef objRef)
    • CfnKeyPair

      protected CfnKeyPair(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • CfnKeyPair

      @Stability(Stable) public CfnKeyPair(@NotNull Construct scope, @NotNull String id, @NotNull CfnKeyPairProps props)
      Create a new AWS::EC2::KeyPair.

      Parameters:
      scope -
      • scope in which this resource is defined.
      This parameter is required.
      id -
      • scoped id of the resource.
      This parameter is required.
      props -
      • resource properties.
      This parameter is required.
  • Method Details

    • inspect

      @Stability(Stable) public void inspect(@NotNull TreeInspector inspector)
      Examines the CloudFormation resource and discloses attributes.

      Specified by:
      inspect in interface IInspectable
      Parameters:
      inspector -
      • tree inspector to collect and process attributes.
      This parameter is required.
    • renderProperties

      @Stability(Stable) @NotNull protected Map<String,Object> renderProperties(@NotNull Map<String,Object> props)
      Overrides:
      renderProperties in class CfnResource
      Parameters:
      props - This parameter is required.
    • getAttrKeyFingerprint

      @Stability(Stable) @NotNull public String getAttrKeyFingerprint()
      If you created the key pair using Amazon EC2:.

      • For RSA key pairs, the key fingerprint is the SHA-1 digest of the DER encoded private key.
      • For ED25519 key pairs, the key fingerprint is the base64-encoded SHA-256 digest, which is the default for OpenSSH, starting with OpenSSH 6.8 .

      If you imported the key pair to Amazon EC2:

      • For RSA key pairs, the key fingerprint is the MD5 public key fingerprint as specified in section 4 of RFC 4716.
      • For ED25519 key pairs, the key fingerprint is the base64-encoded SHA-256 digest, which is the default for OpenSSH, starting with OpenSSH 6.8 .
    • getAttrKeyPairId

      @Stability(Stable) @NotNull public String getAttrKeyPairId()
      The ID of the key pair.
    • getCfnProperties

      @Stability(Stable) @NotNull protected Map<String,Object> getCfnProperties()
      Overrides:
      getCfnProperties in class CfnResource
    • getTags

      @Stability(Stable) @NotNull public TagManager getTags()
      The tags to apply to the key pair.
    • getKeyName

      @Stability(Stable) @NotNull public String getKeyName()
      A unique name for the key pair.

      Constraints: Up to 255 ASCII characters

    • setKeyName

      @Stability(Stable) public void setKeyName(@NotNull String value)
      A unique name for the key pair.

      Constraints: Up to 255 ASCII characters

    • getKeyType

      @Stability(Stable) @Nullable public String getKeyType()
      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

    • setKeyType

      @Stability(Stable) public void setKeyType(@Nullable String value)
      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

    • getPublicKeyMaterial

      @Stability(Stable) @Nullable public String getPublicKeyMaterial()
      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.

    • setPublicKeyMaterial

      @Stability(Stable) public void setPublicKeyMaterial(@Nullable String value)
      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.