KeyPairProps Struct
The properties of a Key Pair.
| Source | aws-ec2/lib/key-pair.ts |
|---|---|
| Type last changed |
Example
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,
});
# 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
)
Vpc vpc;
InstanceType instanceType;
KeyPair keyPair = KeyPair.Builder.create(this, "KeyPair")
.type(KeyPairType.ED25519)
.format(KeyPairFormat.PEM)
.build();
Instance instance = Instance.Builder.create(this, "Instance")
.vpc(vpc)
.instanceType(instanceType)
.machineImage(MachineImage.latestAmazonLinux2023())
// Use the custom key pair
.keyPair(keyPair)
.build();
// Install: dotnet add package Amazon.CDK.Lib
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
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc
var instanceType InstanceType
keyPair := ec2.NewKeyPair(this, jsii.String("KeyPair"), &KeyPairProps{
Type: ec2.KeyPairType_ED25519,
Format: ec2.KeyPairFormat_PEM,
})
instance := ec2.NewInstance(this, jsii.String("Instance"), &InstanceProps{
Vpc: Vpc,
InstanceType: InstanceType,
MachineImage: ec2.MachineImage_LatestAmazonLinux2023(),
// Use the custom key pair
KeyPair: KeyPair,
})
Properties
accountoptionalstringaccountoptionalstraccountoptionalStringAccountoptionalstringAccountoptional*string #Default: the resource is in the same account as the stack it belongs to
environmentFromArnoptionalstringenvironment_from_arnoptionalstrenvironmentFromArnoptionalStringEnvironmentFromArnoptionalstringEnvironmentFromArnoptional*string #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.
formatoptionalKeyPairFormatformatoptionalKeyPairFormatformatoptionalKeyPairFormatFormatoptionalKeyPairFormatFormatoptionalKeyPairFormat = PEM #keyPairNameoptionalstringkey_pair_nameoptionalstrkeyPairNameoptionalStringKeyPairNameoptionalstringKeyPairNameoptional*string #Default: A generated name
physicalNameoptionalstringphysical_nameoptionalstrphysicalNameoptionalStringPhysicalNameoptionalstringPhysicalNameoptional*string #Default: The physical name will be allocated by CloudFormation at deployment time
notes
undefinedimplies that a physical name will be allocated by CloudFormation during deployment.- a concrete value implies a specific physical name
PhysicalName.GENERATE_IF_NEEDEDis 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.
publicKeyMaterialoptionalstringpublic_key_materialoptionalstrpublicKeyMaterialoptionalStringPublicKeyMaterialoptionalstringPublicKeyMaterialoptional*string #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.
regionoptionalstringregionoptionalstrregionoptionalStringRegionoptionalstringRegionoptional*string #Default: the resource is in the same region as the stack it belongs to
typeoptionalKeyPairTypetypeoptionalKeyPairTypetypeoptionalKeyPairTypeTypeoptionalKeyPairTypeTypeoptionalKeyPairType #Default: RSA (ignored if keyMaterial is provided)