class KeyPair (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.EC2.KeyPair |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsec2#KeyPair |
![]() | software.amazon.awscdk.services.ec2.KeyPair |
![]() | aws_cdk.aws_ec2.KeyPair |
![]() | aws-cdk-lib » aws_ec2 » KeyPair |
Implements
IConstruct
, IDependable
, IResource
, IKey
An EC2 Key Pair.
Example
const keyPair = ec2.KeyPair.fromKeyPairAttributes(this, 'KeyPair', {
keyPairName: 'the-keypair-name',
type: ec2.KeyPairType.RSA,
})
Initializer
new KeyPair(scope: Construct, id: string, props?: KeyPairProps)
Parameters
- scope
Construct
- id
string
- props
Key
Pair Props
Construct Props
Name | Type | Description |
---|---|---|
account? | string | The AWS account ID this resource belongs to. |
environment | string | ARN to deduce region and account from. |
format? | Key | The format of the key pair. |
key | string | A unique name for the key pair. |
physical | string | The value passed in by users to the physical name prop of the resource. |
public | string | The public key material. |
region? | string | The AWS region this resource belongs to. |
type? | Key | The type of key pair. |
account?
Type:
string
(optional, default: the resource is in the same account as the stack it belongs to)
The AWS account ID this resource belongs to.
environmentFromArn?
Type:
string
(optional, default: take environment from account
, region
parameters, or use Stack environment.)
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
.
format?
Type:
Key
(optional, default: PEM)
The format of the key pair.
keyPairName?
Type:
string
(optional, default: A generated name)
A unique name for the key pair.
physicalName?
Type:
string
(optional, default: The physical name will be allocated by CloudFormation at deployment time)
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.
publicKeyMaterial?
Type:
string
(optional, default: a public and private key will be generated)
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.
region?
Type:
string
(optional, default: the resource is in the same region as the stack it belongs to)
The AWS region this resource belongs to.
type?
Type:
Key
(optional, default: RSA (ignored if keyMaterial is provided))
The type of key pair.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
format | Key | The format of the key pair. |
has | boolean | Whether the key material was imported. |
key | string | The fingerprint of the key pair. |
key | string | The unique ID of the key pair. |
key | string | The unique name of the key pair. |
node | Node | The tree node. |
private | IString | The Systems Manager Parameter Store parameter with the pair's private key material. |
stack | Stack | The stack in which this resource is defined. |
type? | Key | The type of the key pair. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
format
Type:
Key
The format of the key pair.
hasImportedMaterial
Type:
boolean
Whether the key material was imported.
Keys with imported material do not have their private key material stored or returned automatically.
keyPairFingerprint
Type:
string
The fingerprint of the key pair.
keyPairId
Type:
string
The unique ID of the key pair.
keyPairName
Type:
string
The unique name of the key pair.
node
Type:
Node
The tree node.
privateKey
Type:
IString
The Systems Manager Parameter Store parameter with the pair's private key material.
stack
Type:
Stack
The stack in which this resource is defined.
type?
Type:
Key
(optional)
The type of the key pair.
Methods
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | Imports a key pair with a name and optional type. |
static from | Imports a key pair based on the name. |
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromKeyPairAttributes(scope, id, attrs)
public static fromKeyPairAttributes(scope: Construct, id: string, attrs: KeyPairAttributes): IKeyPair
Parameters
- scope
Construct
- id
string
- attrs
Key
Pair Attributes
Returns
Imports a key pair with a name and optional type.
static fromKeyPairName(scope, id, keyPairName)
public static fromKeyPairName(scope: Construct, id: string, keyPairName: string): IKeyPair
Parameters
- scope
Construct
- id
string
- keyPairName
string
Returns
Imports a key pair based on the name.