aws.ec2.KeyPair
Explore with Pulumi AI
Provides an EC2 key pair resource. A key pair is used to control login access to EC2 instances.
Currently this resource requires an existing user-supplied key pair. This key pair’s public key will be registered with AWS to allow logging-in to EC2 instances.
When importing an existing key pair the public key material may be in any format supported by AWS. Supported formats (per the AWS documentation) are:
- OpenSSH public key format (the format in ~/.ssh/authorized_keys)
- Base64 encoded DER format
- SSH public key file format as specified in RFC4716
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const deployer = new aws.ec2.KeyPair("deployer", {
keyName: "deployer-key",
publicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com",
});
import pulumi
import pulumi_aws as aws
deployer = aws.ec2.KeyPair("deployer",
key_name="deployer-key",
public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com")
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := ec2.NewKeyPair(ctx, "deployer", &ec2.KeyPairArgs{
KeyName: pulumi.String("deployer-key"),
PublicKey: pulumi.String("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com"),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var deployer = new Aws.Ec2.KeyPair("deployer", new()
{
KeyName = "deployer-key",
PublicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.KeyPair;
import com.pulumi.aws.ec2.KeyPairArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var deployer = new KeyPair("deployer", KeyPairArgs.builder()
.keyName("deployer-key")
.publicKey("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com")
.build());
}
}
resources:
deployer:
type: aws:ec2:KeyPair
properties:
keyName: deployer-key
publicKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com
Create KeyPair Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new KeyPair(name: string, args: KeyPairArgs, opts?: CustomResourceOptions);
@overload
def KeyPair(resource_name: str,
args: KeyPairArgs,
opts: Optional[ResourceOptions] = None)
@overload
def KeyPair(resource_name: str,
opts: Optional[ResourceOptions] = None,
public_key: Optional[str] = None,
key_name: Optional[str] = None,
key_name_prefix: Optional[str] = None,
tags: Optional[Mapping[str, str]] = 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:ec2:KeyPair
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- 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.
Constructor example
The following reference example uses placeholder values for all input properties.
var keyPairResource = new Aws.Ec2.KeyPair("keyPairResource", new()
{
PublicKey = "string",
KeyName = "string",
KeyNamePrefix = "string",
Tags =
{
{ "string", "string" },
},
});
example, err := ec2.NewKeyPair(ctx, "keyPairResource", &ec2.KeyPairArgs{
PublicKey: pulumi.String("string"),
KeyName: pulumi.String("string"),
KeyNamePrefix: pulumi.String("string"),
Tags: pulumi.StringMap{
"string": pulumi.String("string"),
},
})
var keyPairResource = new KeyPair("keyPairResource", KeyPairArgs.builder()
.publicKey("string")
.keyName("string")
.keyNamePrefix("string")
.tags(Map.of("string", "string"))
.build());
key_pair_resource = aws.ec2.KeyPair("keyPairResource",
public_key="string",
key_name="string",
key_name_prefix="string",
tags={
"string": "string",
})
const keyPairResource = new aws.ec2.KeyPair("keyPairResource", {
publicKey: "string",
keyName: "string",
keyNamePrefix: "string",
tags: {
string: "string",
},
});
type: aws:ec2:KeyPair
properties:
keyName: string
keyNamePrefix: string
publicKey: string
tags:
string: string
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:
- Public
Key string - The public key material.
- Key
Name string - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Key
Name stringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Dictionary<string, string>
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.
- Public
Key string - The public key material.
- Key
Name string - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Key
Name stringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - map[string]string
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.
- public
Key String - The public key material.
- key
Name String - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Name StringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Map<String,String>
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.
- public
Key string - The public key material.
- key
Name string - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Name stringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - {[key: string]: string}
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.
- public_
key str - The public key material.
- key_
name str - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key_
name_ strprefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Mapping[str, str]
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.
- public
Key String - The public key material.
- key
Name String - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Name StringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Map<String>
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.
Outputs
All input properties are implicitly available as output properties. Additionally, the KeyPair resource produces the following output properties:
- Arn string
- The key pair ARN.
- Fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- Id string
- The provider-assigned unique ID for this managed resource.
- Key
Pair stringId - The key pair ID.
- Key
Type string - The type of key pair.
- Dictionary<string, string>
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- Arn string
- The key pair ARN.
- Fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- Id string
- The provider-assigned unique ID for this managed resource.
- Key
Pair stringId - The key pair ID.
- Key
Type string - The type of key pair.
- map[string]string
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- arn String
- The key pair ARN.
- fingerprint String
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- id String
- The provider-assigned unique ID for this managed resource.
- key
Pair StringId - The key pair ID.
- key
Type String - The type of key pair.
- Map<String,String>
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- arn string
- The key pair ARN.
- fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- id string
- The provider-assigned unique ID for this managed resource.
- key
Pair stringId - The key pair ID.
- key
Type string - The type of key pair.
- {[key: string]: string}
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- arn str
- The key pair ARN.
- fingerprint str
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- id str
- The provider-assigned unique ID for this managed resource.
- key_
pair_ strid - The key pair ID.
- key_
type str - The type of key pair.
- Mapping[str, str]
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- arn String
- The key pair ARN.
- fingerprint String
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- id String
- The provider-assigned unique ID for this managed resource.
- key
Pair StringId - The key pair ID.
- key
Type String - The type of key pair.
- Map<String>
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
Look up Existing KeyPair Resource
Get an existing KeyPair resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: KeyPairState, opts?: CustomResourceOptions): KeyPair
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
arn: Optional[str] = None,
fingerprint: Optional[str] = None,
key_name: Optional[str] = None,
key_name_prefix: Optional[str] = None,
key_pair_id: Optional[str] = None,
key_type: Optional[str] = None,
public_key: Optional[str] = None,
tags: Optional[Mapping[str, str]] = None,
tags_all: Optional[Mapping[str, str]] = None) -> KeyPair
func GetKeyPair(ctx *Context, name string, id IDInput, state *KeyPairState, opts ...ResourceOption) (*KeyPair, error)
public static KeyPair Get(string name, Input<string> id, KeyPairState? state, CustomResourceOptions? opts = null)
public static KeyPair get(String name, Output<String> id, KeyPairState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Arn string
- The key pair ARN.
- Fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- Key
Name string - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Key
Name stringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Key
Pair stringId - The key pair ID.
- Key
Type string - The type of key pair.
- Public
Key string - The public key material.
- Dictionary<string, string>
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level. - Dictionary<string, string>
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- Arn string
- The key pair ARN.
- Fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- Key
Name string - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Key
Name stringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - Key
Pair stringId - The key pair ID.
- Key
Type string - The type of key pair.
- Public
Key string - The public key material.
- map[string]string
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level. - map[string]string
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- arn String
- The key pair ARN.
- fingerprint String
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- key
Name String - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Name StringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Pair StringId - The key pair ID.
- key
Type String - The type of key pair.
- public
Key String - The public key material.
- Map<String,String>
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level. - Map<String,String>
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- arn string
- The key pair ARN.
- fingerprint string
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- key
Name string - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Name stringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Pair stringId - The key pair ID.
- key
Type string - The type of key pair.
- public
Key string - The public key material.
- {[key: string]: string}
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level. - {[key: string]: string}
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- arn str
- The key pair ARN.
- fingerprint str
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- key_
name str - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key_
name_ strprefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key_
pair_ strid - The key pair ID.
- key_
type str - The type of key pair.
- public_
key str - The public key material.
- Mapping[str, str]
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level. - Mapping[str, str]
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
- arn String
- The key pair ARN.
- fingerprint String
- The MD5 public key fingerprint as specified in section 4 of RFC 4716.
- key
Name String - The name for the key pair. If neither
key_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Name StringPrefix - Creates a unique name beginning with the specified prefix. Conflicts with
key_name
. If neitherkey_name
norkey_name_prefix
is provided, the provider will create a unique key name. - key
Pair StringId - The key pair ID.
- key
Type String - The type of key pair.
- public
Key String - The public key material.
- Map<String>
- Key-value map of resource tags. If configured with a provider
default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level. - Map<String>
- A map of tags assigned to the resource, including those inherited from the provider
default_tags
configuration block.
Import
Using pulumi import
, import Key Pairs using the key_name
. For example:
$ pulumi import aws:ec2/keyPair:KeyPair deployer deployer-key
~> NOTE: The AWS API does not include the public key in the response, so pulumi up
will attempt to replace the key pair. There is currently no supported workaround for this limitation.
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
aws
Terraform Provider.