Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ec2): support creating key pairs #28138

Merged
merged 2 commits into from
Dec 20, 2023
Merged

feat(ec2): support creating key pairs #28138

merged 2 commits into from
Dec 20, 2023

Conversation

laurelmay
Copy link
Contributor

This adds support for creating AWS::EC2::KeyPair resources. These are added as a property to Instance, LaunchTemplate, and NatInstance and the older keyName prop is deprecated in favor of the new keyPair: IKeyPair property.

A getter is added to retrieve the SSM parameter that hold the private key for non-imported keys and checks are added to make sure that ED25519 keys are not used with a Windows instance.

Closes #5252.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team November 26, 2023 23:08
@github-actions github-actions bot added star-contributor [Pilot] contributed between 25-49 PRs to the CDK effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. p1 labels Nov 26, 2023
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 27, 2023
@AllanOricil
Copy link

@kylelaker how can I use it locally before they merge it?

@laurelmay
Copy link
Contributor Author

@kylelaker how can I use it locally before they merge it?

@AllanOricil The CfnKeyPair L1 resource already exists. So you can still use that according to the docs and pass its ref attribute in as keyName. Something like:

const keyPair = new ec2.CfnKeyPair(this, 'KeyPair', {
  KeyName: "A-NAME-FOR-KEY",
});

const keyName = keyPair.ref;

And you can pass keyName into anything that accepts that. Since the key material is put into SSM by CloudFormation, you can still access that using the pattern described in the docs.

@AllanOricil
Copy link

@kylelaker thank you! That is exactly what I used! I love cdk!

Copy link
Contributor

mergify bot commented Dec 20, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 20, 2023
Copy link
Contributor

mergify bot commented Dec 20, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 86c215d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 6b3caff into aws:main Dec 20, 2023
9 checks passed
Copy link
Contributor

mergify bot commented Dec 20, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

paulhcsun pushed a commit to paulhcsun/aws-cdk that referenced this pull request Jan 5, 2024
This adds support for creating `AWS::EC2::KeyPair` resources. These are added as a property to `Instance`, `LaunchTemplate`, and `NatInstance` and the older `keyName` prop is deprecated in favor of the new `keyPair: IKeyPair` property.

A getter is added to retrieve the SSM parameter that hold the private key for non-imported keys and checks are added to make sure that ED25519 keys are not used with a Windows instance.

Closes aws#5252.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. p1 star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to add EC2 key-pair
4 participants