key_pairs
Creates, updates, deletes or gets a key_pair
resource or lists key_pairs
in a region
Overview
Name | key_pairs |
Type | Resource |
Description | Specifies a key pair for use with an EC2long instance as follows: + To import an existing key pair, include the PublicKeyMaterial property.+ To create a new key pair, omit the PublicKeyMaterial property.When you import an existing key pair, you specify the public key material for the key. We assume that you have the private key material for the key. CFNlong does not create or return the private key material when you import a key pair. When you create a new key pair, the private key is saved to SYSlong Parameter Store, using a parameter with the following name: /ec2/keypair/{key_pair_id} . For more information about retrieving private key, and the required permissions, see [Create a key pair using](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html#create-key-pair-cloudformation) in the *User Guide*.When CFN deletes a key pair that was created or imported by a stack, it also deletes the parameter that was used to store the private key material in Parameter Store. |
Id | aws.ec2.key_pairs |
Fields
Name | Datatype | Description |
---|---|---|
key_name | string | A unique name for the key pair. Constraints: Up to 255 ASCII characters |
key_type | string | The type of key pair. Note that ED25519 keys are not supported for Windows instances. If the PublicKeyMaterial property is specified, the KeyType property is ignored, and the key type is inferred from the PublicKeyMaterial value.Default: rsa |
key_format | string | The format of the key pair. Default: pem |
public_key_material | string | The public key material. The PublicKeyMaterial property is used to import a key pair. If this property is not specified, then a new key pair will be created. |
key_fingerprint | string | |
key_pair_id | string | |
tags | array | The tags to apply to the key pair. |
region | string | AWS region. |
Methods
Name | Accessible by | Required Params |
---|---|---|
create_resource | INSERT | KeyName, region |
delete_resource | DELETE | data__Identifier, region |
list_resources | SELECT | region |
get_resource | SELECT | data__Identifier, region |
SELECT
examples
Gets all key_pairs
in a region.
SELECT
region,
key_name,
key_type,
key_format,
public_key_material,
key_fingerprint,
key_pair_id,
tags
FROM aws.ec2.key_pairs
WHERE region = 'us-east-1';
Gets all properties from an individual key_pair
.
SELECT
region,
key_name,
key_type,
key_format,
public_key_material,
key_fingerprint,
key_pair_id,
tags
FROM aws.ec2.key_pairs
WHERE region = 'us-east-1' AND data__Identifier = '<KeyName>';
INSERT
example
Use the following StackQL query and manifest file to create a new key_pair
resource, using stack-deploy
.
- Required Properties
- All Properties
- Manifest
/*+ create */
INSERT INTO aws.ec2.key_pairs (
KeyName,
region
)
SELECT
'{{ KeyName }}',
'{{ region }}';
/*+ create */
INSERT INTO aws.ec2.key_pairs (
KeyName,
KeyType,
KeyFormat,
PublicKeyMaterial,
Tags,
region
)
SELECT
'{{ KeyName }}',
'{{ KeyType }}',
'{{ KeyFormat }}',
'{{ PublicKeyMaterial }}',
'{{ Tags }}',
'{{ region }}';
version: 1
name: stack name
description: stack description
providers:
- aws
globals:
- name: region
value: '{{ vars.AWS_REGION }}'
resources:
- name: key_pair
props:
- name: KeyName
value: '{{ KeyName }}'
- name: KeyType
value: '{{ KeyType }}'
- name: KeyFormat
value: '{{ KeyFormat }}'
- name: PublicKeyMaterial
value: '{{ PublicKeyMaterial }}'
- name: Tags
value:
- Key: '{{ Key }}'
Value: '{{ Value }}'
DELETE
example
/*+ delete */
DELETE FROM aws.ec2.key_pairs
WHERE data__Identifier = '<KeyName>'
AND region = 'us-east-1';
Permissions
To operate on the key_pairs
resource, the following permissions are required:
Create
ec2:CreateKeyPair,
ec2:ImportKeyPair,
ec2:CreateTags,
ssm:PutParameter
Read
ec2:DescribeKeyPairs
List
ec2:DescribeKeyPairs
Delete
ec2:DeleteKeyPair,
ssm:DeleteParameter,
ec2:DescribeKeyPairs