- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
DescribeKeyPairsCommand
Describes the specified key pairs or all of your key pairs.
For more information about key pairs, see Amazon EC2 key pairs in the Amazon EC2 User Guide.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { EC2Client, DescribeKeyPairsCommand } from "@aws-sdk/client-ec2"; // ES Modules import
// const { EC2Client, DescribeKeyPairsCommand } = require("@aws-sdk/client-ec2"); // CommonJS import
const client = new EC2Client(config);
const input = { // DescribeKeyPairsRequest
KeyNames: [ // KeyNameStringList
"STRING_VALUE",
],
KeyPairIds: [ // KeyPairIdStringList
"STRING_VALUE",
],
IncludePublicKey: true || false,
DryRun: true || false,
Filters: [ // FilterList
{ // Filter
Name: "STRING_VALUE",
Values: [ // ValueStringList
"STRING_VALUE",
],
},
],
};
const command = new DescribeKeyPairsCommand(input);
const response = await client.send(command);
// { // DescribeKeyPairsResult
// KeyPairs: [ // KeyPairList
// { // KeyPairInfo
// KeyPairId: "STRING_VALUE",
// KeyType: "rsa" || "ed25519",
// Tags: [ // TagList
// { // Tag
// Key: "STRING_VALUE",
// Value: "STRING_VALUE",
// },
// ],
// PublicKey: "STRING_VALUE",
// CreateTime: new Date("TIMESTAMP"),
// KeyName: "STRING_VALUE",
// KeyFingerprint: "STRING_VALUE",
// },
// ],
// };
Example Usage
DescribeKeyPairsCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
DryRun | boolean | undefined | Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is |
Filters | Filter[] | undefined | The filters.
|
IncludePublicKey | boolean | undefined | If Default: |
KeyNames | string[] | undefined | The key pair names. Default: Describes all of your key pairs. |
KeyPairIds | string[] | undefined | The IDs of the key pairs. |
DescribeKeyPairsCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
KeyPairs | KeyPairInfo[] | undefined | Information about the key pairs. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
EC2ServiceException | Base exception class for all service exceptions from EC2 service. |