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 thePublicKeyMaterial 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 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 | awscc.ec2.key_pairs |
Fields
- get (all properties)
- list (identifiers only)
| 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 thePublicKeyMaterial 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. |
| Name | Datatype | Description |
|---|---|---|
key_name | string | A unique name for the key pair.Constraints: Up to 255 ASCII characters |
region | string | AWS region. |
For more information, see AWS::EC2::KeyPair.
Methods
| Name | Resource | Accessible by | Required Params |
|---|---|---|---|
create_resource | key_pairs | INSERT | KeyName, region |
delete_resource | key_pairs | DELETE | Identifier, region |
list_resources | key_pairs_list_only | SELECT | region |
get_resource | key_pairs | SELECT | Identifier, region |
SELECT examples
- get (all properties)
- list (identifiers only)
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 awscc.ec2.key_pairs
WHERE
region = '{{ region }}' AND
Identifier = '{{ key_name }}';
Lists all key_pairs in a region.
SELECT
region,
key_name
FROM awscc.ec2.key_pairs_list_only
WHERE
region = '{{ region }}';
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 awscc.ec2.key_pairs (
KeyName,
region
)
SELECT
'{{ key_name }}',
'{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
/*+ create */
INSERT INTO awscc.ec2.key_pairs (
KeyName,
KeyType,
KeyFormat,
PublicKeyMaterial,
Tags,
region
)
SELECT
'{{ key_name }}',
'{{ key_type }}',
'{{ key_format }}',
'{{ public_key_material }}',
'{{ tags }}',
'{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
version: 1
name: stack name
description: stack description
providers:
- aws
globals:
- name: region
value: '{{ vars.AWS_REGION }}'
resources:
- name: key_pair
props:
- name: key_name
value: '{{ key_name }}'
- name: key_type
value: '{{ key_type }}'
- name: key_format
value: '{{ key_format }}'
- name: public_key_material
value: '{{ public_key_material }}'
- name: tags
value:
- key: '{{ key }}'
value: '{{ value }}'
DELETE example
/*+ delete */
DELETE FROM awscc.ec2.key_pairs
WHERE
Identifier = '{{ key_name }}' AND
region = '{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
Additional Parameters
Mutable resources in the Cloud Control provider support additional optional parameters which can be supplied with INSERT, UPDATE, or DELETE operations. These include:
| Parameter | Description |
|---|---|
ClientToken | A unique identifier to ensure the idempotency of the resource request.This allows the provider to accurately distinguish between retries and new requests.A client token is valid for 36 hours once used. After that, a resource request with the same client token is treated as a new request. If you do not specify a client token, one is generated for inclusion in the request. |
RoleArn | The ARN of the IAM role used to perform this resource operation.The role specified must have the permissions required for this operation.If you do not specify a role, a temporary session is created using your AWS user credentials. |
TypeVersionId | For private resource types, the type version to use in this resource operation.If you do not specify a resource version, the default version is used. |
Permissions
To operate on the key_pairs resource, the following permissions are required:
- Create
- Read
- List
- Delete
ec2:CreateKeyPair,
ec2:ImportKeyPair,
ec2:CreateTags,
ssm:PutParameter
ec2:DescribeKeyPairs
ec2:DescribeKeyPairs
ec2:DeleteKeyPair,
ssm:DeleteParameter,
ec2:DescribeKeyPairs