runway.cfngin.hooks.keypair module

AWS EC2 keypair hook.

class runway.cfngin.hooks.keypair.KeyPairInfo(_typename, _fields=None, /, **kwargs)[source]

Bases: dict

Value returned from get_existing_key_pair.

runway.cfngin.hooks.keypair.get_existing_key_pair(ec2: EC2Client, keypair_name: str)Optional[KeyPairInfo][source]

Get existing keypair.

runway.cfngin.hooks.keypair.import_key_pair(ec2: EC2Client, keypair_name: str, public_key_data: bytes)ImportKeyPairResultTypeDef[source]

Import keypair.

runway.cfngin.hooks.keypair.read_public_key_file(path: Path)Optional[bytes][source]

Read public key file.

runway.cfngin.hooks.keypair.create_key_pair_from_public_key_file(ec2: EC2Client, keypair_name: str, public_key_path: Path)Optional[KeyPairInfo][source]

Create keypair from public key file.

runway.cfngin.hooks.keypair.create_key_pair_in_ssm(ec2: EC2Client, ssm: SSMClient, keypair_name: str, parameter_name: str, kms_key_id: Optional[str] = None)Optional[KeyPairInfo][source]

Create keypair in SSM.

runway.cfngin.hooks.keypair.create_key_pair(ec2: EC2Client, keypair_name: str)KeyPairTypeDef[source]

Create keypair.

runway.cfngin.hooks.keypair.create_key_pair_local(ec2: EC2Client, keypair_name: str, dest_dir: Path)Optional[KeyPairInfo][source]

Create local keypair.

runway.cfngin.hooks.keypair.interactive_prompt(keypair_name: str)Tuple[Optional[Literal[create, import]], Optional[str]][source]

Interactive prompt.

runway.cfngin.hooks.keypair.ensure_keypair_exists(context: CfnginContext, *, keypair: str, public_key_path: Optional[str] = None, ssm_key_id: Optional[str] = None, ssm_parameter_name: Optional[str] = None, **_: Any)KeyPairInfo[source]

Ensure a specific keypair exists within AWS.

If the key doesn’t exist, upload it.

  • context – Context instance. (passed in by CFNgin)

  • keypair – Name of the key pair to create

  • public_key_path – Path to a public key file to be imported instead of generating a new key. Incompatible with the SSM options, as the private key will not be available for storing.

  • ssm_key_id – ID of a KMS key to encrypt the SSM parameter with. If omitted, the default key will be used.

  • ssm_parameter_name – Path to an SSM store parameter to receive the generated private key, instead of importing it or storing it locally.