1. Packages
  2. AWS Native
  3. API Docs
  4. ec2
  5. KeyPair

AWS Native is in preview. AWS Classic is fully supported.

AWS Native v0.100.0 published on Wednesday, Mar 27, 2024 by Pulumi

aws-native.ec2.KeyPair

Explore with Pulumi AI

aws-native logo

AWS Native is in preview. AWS Classic is fully supported.

AWS Native v0.100.0 published on Wednesday, Mar 27, 2024 by Pulumi

    The AWS::EC2::KeyPair creates an SSH key pair

    Example Usage

    Example

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AwsNative = Pulumi.AwsNative;
    
    return await Deployment.RunAsync(() => 
    {
        var newKeyPair = new AwsNative.Ec2.KeyPair("newKeyPair", new()
        {
            KeyName = "MyKeyPair",
        });
    
        var ec2Instance = new AwsNative.Ec2.Instance("ec2Instance", new()
        {
            ImageId = "ami-02b92c281a4d3dc79",
            KeyName = newKeyPair.Id,
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws-native/sdk/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		newKeyPair, err := ec2.NewKeyPair(ctx, "newKeyPair", &ec2.KeyPairArgs{
    			KeyName: pulumi.String("MyKeyPair"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ec2.NewInstance(ctx, "ec2Instance", &ec2.InstanceArgs{
    			ImageId: pulumi.String("ami-02b92c281a4d3dc79"),
    			KeyName: newKeyPair.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    

    Coming soon!

    import pulumi
    import pulumi_aws_native as aws_native
    
    new_key_pair = aws_native.ec2.KeyPair("newKeyPair", key_name="MyKeyPair")
    ec2_instance = aws_native.ec2.Instance("ec2Instance",
        image_id="ami-02b92c281a4d3dc79",
        key_name=new_key_pair.id)
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws_native from "@pulumi/aws-native";
    
    const newKeyPair = new aws_native.ec2.KeyPair("newKeyPair", {keyName: "MyKeyPair"});
    const ec2Instance = new aws_native.ec2.Instance("ec2Instance", {
        imageId: "ami-02b92c281a4d3dc79",
        keyName: newKeyPair.id,
    });
    

    Coming soon!

    Example

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AwsNative = Pulumi.AwsNative;
    
    return await Deployment.RunAsync(() => 
    {
        var newKeyPair = new AwsNative.Ec2.KeyPair("newKeyPair", new()
        {
            KeyName = "MyKeyPair",
        });
    
        var ec2Instance = new AwsNative.Ec2.Instance("ec2Instance", new()
        {
            ImageId = "ami-02b92c281a4d3dc79",
            KeyName = newKeyPair.Id,
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws-native/sdk/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		newKeyPair, err := ec2.NewKeyPair(ctx, "newKeyPair", &ec2.KeyPairArgs{
    			KeyName: pulumi.String("MyKeyPair"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ec2.NewInstance(ctx, "ec2Instance", &ec2.InstanceArgs{
    			ImageId: pulumi.String("ami-02b92c281a4d3dc79"),
    			KeyName: newKeyPair.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    

    Coming soon!

    import pulumi
    import pulumi_aws_native as aws_native
    
    new_key_pair = aws_native.ec2.KeyPair("newKeyPair", key_name="MyKeyPair")
    ec2_instance = aws_native.ec2.Instance("ec2Instance",
        image_id="ami-02b92c281a4d3dc79",
        key_name=new_key_pair.id)
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws_native from "@pulumi/aws-native";
    
    const newKeyPair = new aws_native.ec2.KeyPair("newKeyPair", {keyName: "MyKeyPair"});
    const ec2Instance = new aws_native.ec2.Instance("ec2Instance", {
        imageId: "ami-02b92c281a4d3dc79",
        keyName: newKeyPair.id,
    });
    

    Coming soon!

    Example

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AwsNative = Pulumi.AwsNative;
    
    return await Deployment.RunAsync(() => 
    {
        var importedKeyPair = new AwsNative.Ec2.KeyPair("importedKeyPair", new()
        {
            KeyName = "NameForMyImportedKeyPair",
            PublicKeyMaterial = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example",
        });
    
        var ec2Instance = new AwsNative.Ec2.Instance("ec2Instance", new()
        {
            ImageId = "ami-02b92c281a4d3dc79",
            KeyName = importedKeyPair.Id,
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws-native/sdk/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		importedKeyPair, err := ec2.NewKeyPair(ctx, "importedKeyPair", &ec2.KeyPairArgs{
    			KeyName:           pulumi.String("NameForMyImportedKeyPair"),
    			PublicKeyMaterial: pulumi.String("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ec2.NewInstance(ctx, "ec2Instance", &ec2.InstanceArgs{
    			ImageId: pulumi.String("ami-02b92c281a4d3dc79"),
    			KeyName: importedKeyPair.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    

    Coming soon!

    import pulumi
    import pulumi_aws_native as aws_native
    
    imported_key_pair = aws_native.ec2.KeyPair("importedKeyPair",
        key_name="NameForMyImportedKeyPair",
        public_key_material="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example")
    ec2_instance = aws_native.ec2.Instance("ec2Instance",
        image_id="ami-02b92c281a4d3dc79",
        key_name=imported_key_pair.id)
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws_native from "@pulumi/aws-native";
    
    const importedKeyPair = new aws_native.ec2.KeyPair("importedKeyPair", {
        keyName: "NameForMyImportedKeyPair",
        publicKeyMaterial: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example",
    });
    const ec2Instance = new aws_native.ec2.Instance("ec2Instance", {
        imageId: "ami-02b92c281a4d3dc79",
        keyName: importedKeyPair.id,
    });
    

    Coming soon!

    Example

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AwsNative = Pulumi.AwsNative;
    
    return await Deployment.RunAsync(() => 
    {
        var importedKeyPair = new AwsNative.Ec2.KeyPair("importedKeyPair", new()
        {
            KeyName = "NameForMyImportedKeyPair",
            PublicKeyMaterial = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example",
        });
    
        var ec2Instance = new AwsNative.Ec2.Instance("ec2Instance", new()
        {
            ImageId = "ami-02b92c281a4d3dc79",
            KeyName = importedKeyPair.Id,
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws-native/sdk/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		importedKeyPair, err := ec2.NewKeyPair(ctx, "importedKeyPair", &ec2.KeyPairArgs{
    			KeyName:           pulumi.String("NameForMyImportedKeyPair"),
    			PublicKeyMaterial: pulumi.String("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ec2.NewInstance(ctx, "ec2Instance", &ec2.InstanceArgs{
    			ImageId: pulumi.String("ami-02b92c281a4d3dc79"),
    			KeyName: importedKeyPair.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    

    Coming soon!

    import pulumi
    import pulumi_aws_native as aws_native
    
    imported_key_pair = aws_native.ec2.KeyPair("importedKeyPair",
        key_name="NameForMyImportedKeyPair",
        public_key_material="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example")
    ec2_instance = aws_native.ec2.Instance("ec2Instance",
        image_id="ami-02b92c281a4d3dc79",
        key_name=imported_key_pair.id)
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws_native from "@pulumi/aws-native";
    
    const importedKeyPair = new aws_native.ec2.KeyPair("importedKeyPair", {
        keyName: "NameForMyImportedKeyPair",
        publicKeyMaterial: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example",
    });
    const ec2Instance = new aws_native.ec2.Instance("ec2Instance", {
        imageId: "ami-02b92c281a4d3dc79",
        keyName: importedKeyPair.id,
    });
    

    Coming soon!

    Create KeyPair Resource

    new KeyPair(name: string, args: KeyPairArgs, opts?: CustomResourceOptions);
    @overload
    def KeyPair(resource_name: str,
                opts: Optional[ResourceOptions] = None,
                key_format: Optional[KeyPairKeyFormat] = None,
                key_name: Optional[str] = None,
                key_type: Optional[KeyPairKeyType] = None,
                public_key_material: Optional[str] = None,
                tags: Optional[Sequence[_root_inputs.CreateOnlyTagArgs]] = None)
    @overload
    def KeyPair(resource_name: str,
                args: KeyPairArgs,
                opts: Optional[ResourceOptions] = None)
    func NewKeyPair(ctx *Context, name string, args KeyPairArgs, opts ...ResourceOption) (*KeyPair, error)
    public KeyPair(string name, KeyPairArgs args, CustomResourceOptions? opts = null)
    public KeyPair(String name, KeyPairArgs args)
    public KeyPair(String name, KeyPairArgs args, CustomResourceOptions options)
    
    type: aws-native:ec2:KeyPair
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args KeyPairArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args KeyPairArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args KeyPairArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args KeyPairArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args KeyPairArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    KeyPair Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The KeyPair resource accepts the following input properties:

    KeyName string
    The name of the SSH key pair
    KeyFormat Pulumi.AwsNative.Ec2.KeyPairKeyFormat
    The format of the private key
    KeyType Pulumi.AwsNative.Ec2.KeyPairKeyType
    The crypto-system used to generate a key pair.
    PublicKeyMaterial string
    Plain text public key to import
    Tags List<Pulumi.AwsNative.Inputs.CreateOnlyTag>
    An array of key-value pairs to apply to this resource.
    KeyName string
    The name of the SSH key pair
    KeyFormat KeyPairKeyFormat
    The format of the private key
    KeyType KeyPairKeyType
    The crypto-system used to generate a key pair.
    PublicKeyMaterial string
    Plain text public key to import
    Tags CreateOnlyTagArgs
    An array of key-value pairs to apply to this resource.
    keyName String
    The name of the SSH key pair
    keyFormat KeyPairKeyFormat
    The format of the private key
    keyType KeyPairKeyType
    The crypto-system used to generate a key pair.
    publicKeyMaterial String
    Plain text public key to import
    tags List<CreateOnlyTag>
    An array of key-value pairs to apply to this resource.
    keyName string
    The name of the SSH key pair
    keyFormat KeyPairKeyFormat
    The format of the private key
    keyType KeyPairKeyType
    The crypto-system used to generate a key pair.
    publicKeyMaterial string
    Plain text public key to import
    tags CreateOnlyTag[]
    An array of key-value pairs to apply to this resource.
    key_name str
    The name of the SSH key pair
    key_format KeyPairKeyFormat
    The format of the private key
    key_type KeyPairKeyType
    The crypto-system used to generate a key pair.
    public_key_material str
    Plain text public key to import
    tags CreateOnlyTagArgs]
    An array of key-value pairs to apply to this resource.
    keyName String
    The name of the SSH key pair
    keyFormat "pem" | "ppk"
    The format of the private key
    keyType "rsa" | "ed25519"
    The crypto-system used to generate a key pair.
    publicKeyMaterial String
    Plain text public key to import
    tags List<Property Map>
    An array of key-value pairs to apply to this resource.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the KeyPair resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    KeyFingerprint string
    A short sequence of bytes used for public key verification
    KeyPairId string
    An AWS generated ID for the key pair
    Id string
    The provider-assigned unique ID for this managed resource.
    KeyFingerprint string
    A short sequence of bytes used for public key verification
    KeyPairId string
    An AWS generated ID for the key pair
    id String
    The provider-assigned unique ID for this managed resource.
    keyFingerprint String
    A short sequence of bytes used for public key verification
    keyPairId String
    An AWS generated ID for the key pair
    id string
    The provider-assigned unique ID for this managed resource.
    keyFingerprint string
    A short sequence of bytes used for public key verification
    keyPairId string
    An AWS generated ID for the key pair
    id str
    The provider-assigned unique ID for this managed resource.
    key_fingerprint str
    A short sequence of bytes used for public key verification
    key_pair_id str
    An AWS generated ID for the key pair
    id String
    The provider-assigned unique ID for this managed resource.
    keyFingerprint String
    A short sequence of bytes used for public key verification
    keyPairId String
    An AWS generated ID for the key pair

    Supporting Types

    CreateOnlyTag, CreateOnlyTagArgs

    Key string
    The key name of the tag
    Value string
    The value of the tag
    Key string
    The key name of the tag
    Value string
    The value of the tag
    key String
    The key name of the tag
    value String
    The value of the tag
    key string
    The key name of the tag
    value string
    The value of the tag
    key str
    The key name of the tag
    value str
    The value of the tag
    key String
    The key name of the tag
    value String
    The value of the tag

    KeyPairKeyFormat, KeyPairKeyFormatArgs

    Pem
    pem
    Ppk
    ppk
    KeyPairKeyFormatPem
    pem
    KeyPairKeyFormatPpk
    ppk
    Pem
    pem
    Ppk
    ppk
    Pem
    pem
    Ppk
    ppk
    PEM
    pem
    PPK
    ppk
    "pem"
    pem
    "ppk"
    ppk

    KeyPairKeyType, KeyPairKeyTypeArgs

    Rsa
    rsa
    Ed25519
    ed25519
    KeyPairKeyTypeRsa
    rsa
    KeyPairKeyTypeEd25519
    ed25519
    Rsa
    rsa
    Ed25519
    ed25519
    Rsa
    rsa
    Ed25519
    ed25519
    RSA
    rsa
    ED25519
    ed25519
    "rsa"
    rsa
    "ed25519"
    ed25519

    Package Details

    Repository
    AWS Native pulumi/pulumi-aws-native
    License
    Apache-2.0
    aws-native logo

    AWS Native is in preview. AWS Classic is fully supported.

    AWS Native v0.100.0 published on Wednesday, Mar 27, 2024 by Pulumi