get Key Pair
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);
Content copied to clipboard
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)
Content copied to clipboard
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),
};
});
Content copied to clipboard
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
})
}
Content copied to clipboard
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()));
}
}
Content copied to clipboard
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}
Content copied to clipboard
Return
A collection of values returned by getKeyPair.
Parameters
argument
A collection of arguments for invoking getKeyPair.
suspend fun getKeyPair(filters: List<GetKeyPairFilter>? = null, includePublicKey: Boolean? = null, keyName: String? = null, keyPairId: String? = null, tags: Map<String, String>? = null): GetKeyPairResult
Return
A collection of values returned by getKeyPair.
Parameters
filters
Custom filter block as described below.
include Public Key
Whether to include the public key material in the response.
key Name
Key Pair name.
key Pair Id
Key Pair ID.
tags
Any tags assigned to the Key Pair.
See also
Return
A collection of values returned by getKeyPair.
Parameters
argument
Builder for com.pulumi.aws.ec2.kotlin.inputs.GetKeyPairPlainArgs.