1. Packages
  2. AWS Classic
  3. API Docs
  4. ec2
  5. getKeyPair

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi

aws.ec2.getKeyPair

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi

    Use this data source to get information about a specific EC2 Key Pair.

    Example Usage

    The following example shows how to get a EC2 Key Pair including the public key material from its name.

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const example = aws.ec2.getKeyPair({
        keyName: "test",
        includePublicKey: true,
        filters: [{
            name: "tag:Component",
            values: ["web"],
        }],
    });
    export const fingerprint = example.then(example => example.fingerprint);
    export const name = example.then(example => example.keyName);
    export const id = example.then(example => example.id);
    
    import pulumi
    import pulumi_aws as aws
    
    example = aws.ec2.get_key_pair(key_name="test",
        include_public_key=True,
        filters=[{
            "name": "tag:Component",
            "values": ["web"],
        }])
    pulumi.export("fingerprint", example.fingerprint)
    pulumi.export("name", example.key_name)
    pulumi.export("id", example.id)
    
    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 {
    		example, err := ec2.LookupKeyPair(ctx, &ec2.LookupKeyPairArgs{
    			KeyName:          pulumi.StringRef("test"),
    			IncludePublicKey: pulumi.BoolRef(true),
    			Filters: []ec2.GetKeyPairFilter{
    				{
    					Name: "tag:Component",
    					Values: []string{
    						"web",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		ctx.Export("fingerprint", example.Fingerprint)
    		ctx.Export("name", example.KeyName)
    		ctx.Export("id", example.Id)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var example = Aws.Ec2.GetKeyPair.Invoke(new()
        {
            KeyName = "test",
            IncludePublicKey = true,
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetKeyPairFilterInputArgs
                {
                    Name = "tag:Component",
                    Values = new[]
                    {
                        "web",
                    },
                },
            },
        });
    
        return new Dictionary<string, object?>
        {
            ["fingerprint"] = example.Apply(getKeyPairResult => getKeyPairResult.Fingerprint),
            ["name"] = example.Apply(getKeyPairResult => getKeyPairResult.KeyName),
            ["id"] = example.Apply(getKeyPairResult => getKeyPairResult.Id),
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.ec2.Ec2Functions;
    import com.pulumi.aws.ec2.inputs.GetKeyPairArgs;
    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) {
            final var example = Ec2Functions.getKeyPair(GetKeyPairArgs.builder()
                .keyName("test")
                .includePublicKey(true)
                .filters(GetKeyPairFilterArgs.builder()
                    .name("tag:Component")
                    .values("web")
                    .build())
                .build());
    
            ctx.export("fingerprint", example.applyValue(getKeyPairResult -> getKeyPairResult.fingerprint()));
            ctx.export("name", example.applyValue(getKeyPairResult -> getKeyPairResult.keyName()));
            ctx.export("id", example.applyValue(getKeyPairResult -> getKeyPairResult.id()));
        }
    }
    
    variables:
      example:
        fn::invoke:
          Function: aws:ec2:getKeyPair
          Arguments:
            keyName: test
            includePublicKey: true
            filters:
              - name: tag:Component
                values:
                  - web
    outputs:
      fingerprint: ${example.fingerprint}
      name: ${example.keyName}
      id: ${example.id}
    

    Using getKeyPair

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getKeyPair(args: GetKeyPairArgs, opts?: InvokeOptions): Promise<GetKeyPairResult>
    function getKeyPairOutput(args: GetKeyPairOutputArgs, opts?: InvokeOptions): Output<GetKeyPairResult>
    def get_key_pair(filters: Optional[Sequence[GetKeyPairFilter]] = None,
                     include_public_key: Optional[bool] = None,
                     key_name: Optional[str] = None,
                     key_pair_id: Optional[str] = None,
                     tags: Optional[Mapping[str, str]] = None,
                     opts: Optional[InvokeOptions] = None) -> GetKeyPairResult
    def get_key_pair_output(filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetKeyPairFilterArgs]]]] = None,
                     include_public_key: Optional[pulumi.Input[bool]] = None,
                     key_name: Optional[pulumi.Input[str]] = None,
                     key_pair_id: Optional[pulumi.Input[str]] = None,
                     tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                     opts: Optional[InvokeOptions] = None) -> Output[GetKeyPairResult]
    func LookupKeyPair(ctx *Context, args *LookupKeyPairArgs, opts ...InvokeOption) (*LookupKeyPairResult, error)
    func LookupKeyPairOutput(ctx *Context, args *LookupKeyPairOutputArgs, opts ...InvokeOption) LookupKeyPairResultOutput

    > Note: This function is named LookupKeyPair in the Go SDK.

    public static class GetKeyPair 
    {
        public static Task<GetKeyPairResult> InvokeAsync(GetKeyPairArgs args, InvokeOptions? opts = null)
        public static Output<GetKeyPairResult> Invoke(GetKeyPairInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetKeyPairResult> getKeyPair(GetKeyPairArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: aws:ec2/getKeyPair:getKeyPair
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Filters List<GetKeyPairFilter>
    Custom filter block as described below.
    IncludePublicKey bool
    Whether to include the public key material in the response.
    KeyName string
    Key Pair name.
    KeyPairId string
    Key Pair ID.
    Tags Dictionary<string, string>
    Any tags assigned to the Key Pair.
    Filters []GetKeyPairFilter
    Custom filter block as described below.
    IncludePublicKey bool
    Whether to include the public key material in the response.
    KeyName string
    Key Pair name.
    KeyPairId string
    Key Pair ID.
    Tags map[string]string
    Any tags assigned to the Key Pair.
    filters List<GetKeyPairFilter>
    Custom filter block as described below.
    includePublicKey Boolean
    Whether to include the public key material in the response.
    keyName String
    Key Pair name.
    keyPairId String
    Key Pair ID.
    tags Map<String,String>
    Any tags assigned to the Key Pair.
    filters GetKeyPairFilter[]
    Custom filter block as described below.
    includePublicKey boolean
    Whether to include the public key material in the response.
    keyName string
    Key Pair name.
    keyPairId string
    Key Pair ID.
    tags {[key: string]: string}
    Any tags assigned to the Key Pair.
    filters Sequence[GetKeyPairFilter]
    Custom filter block as described below.
    include_public_key bool
    Whether to include the public key material in the response.
    key_name str
    Key Pair name.
    key_pair_id str
    Key Pair ID.
    tags Mapping[str, str]
    Any tags assigned to the Key Pair.
    filters List<Property Map>
    Custom filter block as described below.
    includePublicKey Boolean
    Whether to include the public key material in the response.
    keyName String
    Key Pair name.
    keyPairId String
    Key Pair ID.
    tags Map<String>
    Any tags assigned to the Key Pair.

    getKeyPair Result

    The following output properties are available:

    Arn string
    ARN of the Key Pair.
    CreateTime string
    Timestamp for when the key pair was created in ISO 8601 format.
    Fingerprint string
    SHA-1 digest of the DER encoded private key.
    Id string
    The provider-assigned unique ID for this managed resource.
    KeyType string
    Type of key pair.
    PublicKey string
    Public key material.
    Tags Dictionary<string, string>
    Any tags assigned to the Key Pair.
    Filters List<GetKeyPairFilter>
    IncludePublicKey bool
    KeyName string
    KeyPairId string
    Arn string
    ARN of the Key Pair.
    CreateTime string
    Timestamp for when the key pair was created in ISO 8601 format.
    Fingerprint string
    SHA-1 digest of the DER encoded private key.
    Id string
    The provider-assigned unique ID for this managed resource.
    KeyType string
    Type of key pair.
    PublicKey string
    Public key material.
    Tags map[string]string
    Any tags assigned to the Key Pair.
    Filters []GetKeyPairFilter
    IncludePublicKey bool
    KeyName string
    KeyPairId string
    arn String
    ARN of the Key Pair.
    createTime String
    Timestamp for when the key pair was created in ISO 8601 format.
    fingerprint String
    SHA-1 digest of the DER encoded private key.
    id String
    The provider-assigned unique ID for this managed resource.
    keyType String
    Type of key pair.
    publicKey String
    Public key material.
    tags Map<String,String>
    Any tags assigned to the Key Pair.
    filters List<GetKeyPairFilter>
    includePublicKey Boolean
    keyName String
    keyPairId String
    arn string
    ARN of the Key Pair.
    createTime string
    Timestamp for when the key pair was created in ISO 8601 format.
    fingerprint string
    SHA-1 digest of the DER encoded private key.
    id string
    The provider-assigned unique ID for this managed resource.
    keyType string
    Type of key pair.
    publicKey string
    Public key material.
    tags {[key: string]: string}
    Any tags assigned to the Key Pair.
    filters GetKeyPairFilter[]
    includePublicKey boolean
    keyName string
    keyPairId string
    arn str
    ARN of the Key Pair.
    create_time str
    Timestamp for when the key pair was created in ISO 8601 format.
    fingerprint str
    SHA-1 digest of the DER encoded private key.
    id str
    The provider-assigned unique ID for this managed resource.
    key_type str
    Type of key pair.
    public_key str
    Public key material.
    tags Mapping[str, str]
    Any tags assigned to the Key Pair.
    filters Sequence[GetKeyPairFilter]
    include_public_key bool
    key_name str
    key_pair_id str
    arn String
    ARN of the Key Pair.
    createTime String
    Timestamp for when the key pair was created in ISO 8601 format.
    fingerprint String
    SHA-1 digest of the DER encoded private key.
    id String
    The provider-assigned unique ID for this managed resource.
    keyType String
    Type of key pair.
    publicKey String
    Public key material.
    tags Map<String>
    Any tags assigned to the Key Pair.
    filters List<Property Map>
    includePublicKey Boolean
    keyName String
    keyPairId String

    Supporting Types

    GetKeyPairFilter

    Name string
    Name of the filter field. Valid values can be found in the EC2 DescribeKeyPairs API Reference.
    Values List<string>
    Set of values that are accepted for the given filter field. Results will be selected if any given value matches.
    Name string
    Name of the filter field. Valid values can be found in the EC2 DescribeKeyPairs API Reference.
    Values []string
    Set of values that are accepted for the given filter field. Results will be selected if any given value matches.
    name String
    Name of the filter field. Valid values can be found in the EC2 DescribeKeyPairs API Reference.
    values List<String>
    Set of values that are accepted for the given filter field. Results will be selected if any given value matches.
    name string
    Name of the filter field. Valid values can be found in the EC2 DescribeKeyPairs API Reference.
    values string[]
    Set of values that are accepted for the given filter field. Results will be selected if any given value matches.
    name str
    Name of the filter field. Valid values can be found in the EC2 DescribeKeyPairs API Reference.
    values Sequence[str]
    Set of values that are accepted for the given filter field. Results will be selected if any given value matches.
    name String
    Name of the filter field. Valid values can be found in the EC2 DescribeKeyPairs API Reference.
    values List<String>
    Set of values that are accepted for the given filter field. Results will be selected if any given value matches.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi