Try AWS Native preview for resources not in the classic version.
aws.ec2.getKeyPair
Explore with Pulumi AI
Try AWS Native preview for resources not in the classic version.
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<Get
Key Pair Filter> - Custom filter block as described below.
- Include
Public boolKey - Whether to include the public key material in the response.
- Key
Name string - Key Pair name.
- Key
Pair stringId - Key Pair ID.
- Dictionary<string, string>
- Any tags assigned to the Key Pair.
- Filters
[]Get
Key Pair Filter - Custom filter block as described below.
- Include
Public boolKey - Whether to include the public key material in the response.
- Key
Name string - Key Pair name.
- Key
Pair stringId - Key Pair ID.
- map[string]string
- Any tags assigned to the Key Pair.
- filters
List<Get
Key Pair Filter> - Custom filter block as described below.
- include
Public BooleanKey - Whether to include the public key material in the response.
- key
Name String - Key Pair name.
- key
Pair StringId - Key Pair ID.
- Map<String,String>
- Any tags assigned to the Key Pair.
- filters
Get
Key Pair Filter[] - Custom filter block as described below.
- include
Public booleanKey - Whether to include the public key material in the response.
- key
Name string - Key Pair name.
- key
Pair stringId - Key Pair ID.
- {[key: string]: string}
- Any tags assigned to the Key Pair.
- filters
Sequence[Get
Key Pair Filter] - Custom filter block as described below.
- include_
public_ boolkey - Whether to include the public key material in the response.
- key_
name str - Key Pair name.
- key_
pair_ strid - Key Pair ID.
- Mapping[str, str]
- Any tags assigned to the Key Pair.
- filters List<Property Map>
- Custom filter block as described below.
- include
Public BooleanKey - Whether to include the public key material in the response.
- key
Name String - Key Pair name.
- key
Pair StringId - Key Pair ID.
- Map<String>
- Any tags assigned to the Key Pair.
getKeyPair Result
The following output properties are available:
- Arn string
- ARN of the Key Pair.
- Create
Time 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.
- Key
Type string - Type of key pair.
- Public
Key string - Public key material.
- Dictionary<string, string>
- Any tags assigned to the Key Pair.
- Filters
List<Get
Key Pair Filter> - Include
Public boolKey - Key
Name string - Key
Pair stringId
- Arn string
- ARN of the Key Pair.
- Create
Time 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.
- Key
Type string - Type of key pair.
- Public
Key string - Public key material.
- map[string]string
- Any tags assigned to the Key Pair.
- Filters
[]Get
Key Pair Filter - Include
Public boolKey - Key
Name string - Key
Pair stringId
- arn String
- ARN of the Key Pair.
- create
Time 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.
- key
Type String - Type of key pair.
- public
Key String - Public key material.
- Map<String,String>
- Any tags assigned to the Key Pair.
- filters
List<Get
Key Pair Filter> - include
Public BooleanKey - key
Name String - key
Pair StringId
- arn string
- ARN of the Key Pair.
- create
Time 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.
- key
Type string - Type of key pair.
- public
Key string - Public key material.
- {[key: string]: string}
- Any tags assigned to the Key Pair.
- filters
Get
Key Pair Filter[] - include
Public booleanKey - key
Name string - key
Pair stringId
- 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.
- Mapping[str, str]
- Any tags assigned to the Key Pair.
- filters
Sequence[Get
Key Pair Filter] - include_
public_ boolkey - key_
name str - key_
pair_ strid
- arn String
- ARN of the Key Pair.
- create
Time 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.
- key
Type String - Type of key pair.
- public
Key String - Public key material.
- Map<String>
- Any tags assigned to the Key Pair.
- filters List<Property Map>
- include
Public BooleanKey - key
Name String - key
Pair StringId
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.
Try AWS Native preview for resources not in the classic version.