CDK Construct for managing EC2 key pairs
Project description
CDK EC2 Key Pair
AWS CDK L3 construct for managing EC2 Key Pairs.
CloudFormation doesn't directly support creation of EC2 Key Pairs. This construct provides an easy interface for creating Key Pairs through a custom CloudFormation resource. The private key is stored in AWS Secrets Manager.
Installation
This package has peer dependencies, which need to be installed along in the expected version.
For TypeScript/NodeJS, add these to your dependencies
in package.json
:
- cdk-ec2-key-pair
- @aws-cdk/aws-cloudformation
- @aws-cdk/aws-ec2
- @aws-cdk/aws-iam
- @aws-cdk/aws-kms
- @aws-cdk/aws-lambda
For Python, add these to your requirements.txt
:
- cdk-ec2-key-pair
- aws-cdk.aws-cloudformation
- aws-cdk.aws-ec2
- aws-cdk.aws-iam
- aws-cdk.aws-kms
- aws-cdk.aws-lambda
Usage
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.core as cdk
import aws_cdk.aws_ec2 as ec2
from cdk_ec2_key_pair import KeyPair
# Create the Key Pair
key = KeyPair(self, "A-Key-Pair",
name="a-key-pair",
description="This is a Key Pair"
)
# Grant read access to the private key to a role or user
key.grant_read(some_role)
# Use Key Pair on an EC2 instance
ec2.Instance(self, "An-Instance", {
"key_name": key.name
})
The private key will be stored in AWS Secrets Manager. The secret name by default is prefixed with ec2-private-key/
, so in this example it will be saved as ec2-private-key/a-key-pair
.
To download the private key via AWS cli you can run:
aws secretsmanager get-secret-value \
--secret-id ec2-private-key/a-key-pair \
--query SecretString \
--output text
Roadmap
- Name should be optional
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cdk_ec2_key_pair-1.7.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9c5bd5191588b1c5df51793c749f70b4bc4fb0f7d32001cf7650b4fc6b6b6c1 |
|
MD5 | 5273f2607ffe230991bc486bcdd9ddfb |
|
BLAKE2b-256 | 2402526f6399deb91a2d3c566d881291cb2700814c09e7a8aad0affc85e1cebd |