Skip to main content

key_pairs

Creates, updates, deletes, gets or lists a key_pairs resource.

Overview

Namekey_pairs
TypeResource
Idaws.ec2.key_pairs

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
create_timestringIf you used Amazon EC2 to create the key pair, this is the date and time when the key was created, in ISO 8601 date-time format, in the UTC time zone. If you imported an existing key pair to Amazon EC2, this is the date and time the key was imported, in ISO 8601 date-time format, in the UTC time zone.
key_fingerprintstringIf you used CreateKeyPair to create the key pair: For RSA key pairs, the key fingerprint is the SHA-1 digest of the DER encoded private key. For ED25519 key pairs, the key fingerprint is the base64-encoded SHA-256 digest, which is the default for OpenSSH, starting with OpenSSH 6.8. If you used ImportKeyPair to provide Amazon Web Services the public key: For RSA key pairs, the key fingerprint is the MD5 public key fingerprint as specified in section 4 of RFC4716. For ED25519 key pairs, the key fingerprint is the base64-encoded SHA-256 digest, which is the default for OpenSSH, starting with OpenSSH 6.8.
key_namestringThe name of the key pair.
key_pair_idstringThe ID of the key pair.
key_typestringThe type of key pair.
public_keystringThe public key material.
tagsstringAny tags applied to the key pair.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
describe_key_pairsselectregionKeyName, KeyPairId, IncludePublicKey, DryRun, FilterDescribes 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.
create_key_pairinsertKeyName, regionKeyType, TagSpecification, KeyFormat, DryRunCreates an ED25519 or 2048-bit RSA key pair with the specified name and in the specified format. Amazon EC2 stores the public key and displays the private key for you to save to a file. The private key is returned as an unencrypted PEM encoded PKCS#1 private key or an unencrypted PPK formatted private key for use with PuTTY. If a key with the specified name already exists, Amazon EC2 returns an error. The key pair returned to you is available only in the Amazon Web Services Region in which you create it. If you prefer, you can create your own key pair using a third-party tool and upload it to any Region using ImportKeyPair. You can have up to 5,000 key pairs per Amazon Web Services Region. For more information, see Amazon EC2 key pairs in the Amazon EC2 User Guide.
delete_key_pairdeleteregionKeyName, KeyPairId, DryRunDeletes the specified key pair, by removing the public key from Amazon EC2.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
KeyNamestringA unique name for the key pair. Constraints: Up to 255 ASCII characters
regionstringAWS region (default: us-east-1)
DryRunbooleanChecks 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 DryRunOperation. Otherwise, it is UnauthorizedOperation.
FilterarrayThe filters. key-pair-id - The ID of the key pair. fingerprint - The fingerprint of the key pair. key-name - The name of the key pair. tag-key - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value. tag:<key> - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key Owner and the value TeamA, specify tag:Owner for the filter name and TeamA for the filter value.
IncludePublicKeybooleanIf true, the public key material is included in the response. Default: false
KeyFormatstringThe format of the key pair. Default: pem
KeyNamestringThe name of the key pair.
KeyPairIdstringThe ID of the key pair.
KeyTypestringThe type of key pair. Note that ED25519 keys are not supported for Windows instances. Default: rsa
TagSpecificationarrayThe tags to apply to the new key pair.

SELECT examples

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.

SELECT
create_time,
key_fingerprint,
key_name,
key_pair_id,
key_type,
public_key,
tags
FROM aws.ec2.key_pairs
WHERE region = '{{ region }}' -- required
AND KeyName = '{{ KeyName }}'
AND KeyPairId = '{{ KeyPairId }}'
AND IncludePublicKey = '{{ IncludePublicKey }}'
AND DryRun = '{{ DryRun }}'
AND Filter = '{{ Filter }}'
;

INSERT examples

Creates an ED25519 or 2048-bit RSA key pair with the specified name and in the specified format. Amazon EC2 stores the public key and displays the private key for you to save to a file. The private key is returned as an unencrypted PEM encoded PKCS#1 private key or an unencrypted PPK formatted private key for use with PuTTY. If a key with the specified name already exists, Amazon EC2 returns an error. The key pair returned to you is available only in the Amazon Web Services Region in which you create it. If you prefer, you can create your own key pair using a third-party tool and upload it to any Region using ImportKeyPair. You can have up to 5,000 key pairs per Amazon Web Services Region. For more information, see Amazon EC2 key pairs in the Amazon EC2 User Guide.

INSERT INTO aws.ec2.key_pairs (
KeyName,
region,
KeyType,
TagSpecification,
KeyFormat,
DryRun
)
SELECT
'{{ KeyName }}',
'{{ region }}',
'{{ KeyType }}',
'{{ TagSpecification }}',
'{{ KeyFormat }}',
'{{ DryRun }}'
RETURNING
key_fingerprint,
key_material,
key_name,
key_pair_id,
tags
;

DELETE examples

Deletes the specified key pair, by removing the public key from Amazon EC2.

DELETE FROM aws.ec2.key_pairs
WHERE region = '{{ region }}' --required
AND KeyName = '{{ KeyName }}'
AND KeyPairId = '{{ KeyPairId }}'
AND DryRun = '{{ DryRun }}'
;