feat(asg): support keypair functionality for asg#29679
feat(asg): support keypair functionality for asg#29679mergify[bot] merged 21 commits intoaws:mainfrom
Conversation
aws-cdk-automation
left a comment
There was a problem hiding this comment.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
lpizzinidev
left a comment
There was a problem hiding this comment.
Thanks 👍
Left some comments for adjustments.
Also, the new property and all added validations should have proper unit test coverage here.
| */ | ||
| readonly keyName?: string; |
There was a problem hiding this comment.
| */ | |
| readonly keyName?: string; | |
| * @deprecated - Use `keyPair` instead - https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2-readme.html#using-an-existing-ec2-key-pair | |
| */ | |
| readonly keyName?: string; |
We should mark the property as deprecated.
| * `keyName`, `launchTemplate` and `mixedInstancesPolicy` must not be specified | ||
| * when this property is specified | ||
| * |
There was a problem hiding this comment.
| * `keyName`, `launchTemplate` and `mixedInstancesPolicy` must not be specified | |
| * when this property is specified | |
| * | |
| * `launchTemplate` and `mixedInstancesPolicy` must not be specified | |
| * when this property is specified. | |
| * | |
| * You can either specify `keyPair` or `keyName`, not both. |
Suggestion for different wording. Can you please update keyName documentation as well?
| /** | ||
| * The SSH keypair to grant access to the instance. | ||
| * | ||
| * `keyName`, `launchTemplate` and `mixedInstancesPolicy` must not be specified |
| spotOptions: props.spotPrice !== undefined ? { maxPrice: parseFloat(props.spotPrice) } : undefined, | ||
| blockDevices: props.blockDevices, | ||
| instanceProfile, | ||
| ...keyUsageType, |
There was a problem hiding this comment.
| ...keyUsageType, | |
| keyName: props.keyPair?.keyPairName ?? props?.keyName, |
Given the above validation, we can simplify this assignment.
There was a problem hiding this comment.
@lpizzinidev The idea of creating the keyUsageType was to send just one of them (keyPair or keyName) to the LaunchTemplate, to avoid sending the keyName if keyPair is set
let keyUsageType: { keyPair?: ec2.IKeyPair; keyName?: string } = {};
if (props.keyPair) {
keyUsageType = { keyPair: props.keyPair };
} else {
keyUsageType = { keyName: props.keyName };
}It makes sense ?
| this.securityGroups = [this.securityGroup]; | ||
|
|
||
| if (props.keyPair) { | ||
| throw new Error('Can only use \'keyPair\' when feature flag \'AUTOSCALING_GENERATE_LAUNCH_TEMPLATE\' is set'); |
There was a problem hiding this comment.
I added this validation because if AUTOSCALING_GENERATE_LAUNCH_TEMPLATE is disabled, a CfnLaunchConfiguration will be created instead LaunchTemplate .. and doesn't have support for the keyPair
There was a problem hiding this comment.
I see, thanks for clarifying! Can you please add it to the documentation of the variable?
| @@ -24,6 +24,7 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { | |||
| Creating an `AutoScalingGroup` from a Launch Configuration has been deprecated. All new accounts created after December 31, 2023 will no longer be able to create Launch Configurations. With the `@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig` feature flag set to true, `AutoScalingGroup` properties used to create a Launch Configuration will now be used to create a `LaunchTemplate` using a [Launch Configuration to `LaunchTemplate` mapping](https://docs.aws.amazon.com/autoscaling/ec2/userguide/migrate-launch-configurations-with-cloudformation.html#launch-configuration-mapping-reference). Specifically, the following `AutoScalingGroup` properties will be used to generate a `LaunchTemplate`: | |||
| * machineImage | |||
| * keyName | |||
There was a problem hiding this comment.
| * keyName | |
| * keyName (deprecated, prefer keyPair) |
Could you please add an example of keyPair usage in the code block below?
lpizzinidev
left a comment
There was a problem hiding this comment.
Thanks for implementing the changes and adding the comments 👍
Left a couple of suggestions.
Plus, we're still missing coverage on unit tests (#29679 (review)).
| spotOptions: props.spotPrice !== undefined ? { maxPrice: parseFloat(props.spotPrice) } : undefined, | ||
| blockDevices: props.blockDevices, | ||
| instanceProfile, | ||
| ...keyUsageType, |
There was a problem hiding this comment.
| ...keyUsageType, | |
| keyPair: props.keyPair, | |
| keyName: props.keyName, |
The idea of creating the keyUsageType was to send just one of them (keyPair or keyName) to the LaunchTemplate, to avoid sending the keyName if keyPair is set
Makes sense, thanks for clarifying!
However, we could simply specify it like this then if I'm not mistaken.
There was a problem hiding this comment.
I tried the way you mentioned, but I believe that because of the LaunchTemplate, when sending the keyName in your constructor, it will display the warning on the screen, even if the user did not define it when creating the ASG 😵💫
[WARNING] aws-cdk-lib.aws_ec2.LaunchTemplateProps#keyName is deprecated.
There was a problem hiding this comment.
Well, that's annoying 🫠
| ...keyUsageType, | |
| keyPair: props.keyPair, | |
| ...{ props.keyName ? { keyName: props.keyName } : {} }, |
I guess this should work then.
Your implementation is correct of course, but I'd like to keep it more concise if possible.
Thanks for following up on this 👍
| this.securityGroups = [this.securityGroup]; | ||
|
|
||
| if (props.keyPair) { | ||
| throw new Error('Can only use \'keyPair\' when feature flag \'AUTOSCALING_GENERATE_LAUNCH_TEMPLATE\' is set'); |
There was a problem hiding this comment.
I see, thanks for clarifying! Can you please add it to the documentation of the variable?
Unit tests add: 51fda7f |
| spotOptions: props.spotPrice !== undefined ? { maxPrice: parseFloat(props.spotPrice) } : undefined, | ||
| blockDevices: props.blockDevices, | ||
| instanceProfile, | ||
| ...keyUsageType, |
There was a problem hiding this comment.
Well, that's annoying 🫠
| ...keyUsageType, | |
| keyPair: props.keyPair, | |
| ...{ props.keyName ? { keyName: props.keyName } : {} }, |
I guess this should work then.
Your implementation is correct of course, but I'd like to keep it more concise if possible.
Thanks for following up on this 👍
@shikha372 I believe I updated the branch by mistake, sorry 😵 |
yeah, manual merge not recommended with mergifyio, i'll see it from here |
|
@Mergifyio update |
❌ Mergify doesn't have permission to updateDetailsFor security reasons, Mergify can't update this pull request. Try updating locally. |
|
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). |
|
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
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). |
|
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one. |
Issue
When creating an instance directly through the asg, it is not possible to define the
keyPair, in addition to bringing a warning message that thekeyNamewill be removedThis configuration allows sending the
keyPairto the asg since the LaunchTemplate allows its integrationWarning:
Closes #29237
Reason for this change
I'm working directly with CDK and needed to implement a way to use my
keyPairand avoid warning thatkeyNamewill be removed soon when i'm creating my ASGDescription of changes
keyPairto CommonAutoScalingGroupProps interfacekeyPairandkeyNamefrom being set at the same timekeyPairwhen creating LaunchTemplate if flagAUTOSCALING_GENERATE_LAUNCH_TEMPLATEis enabledkeyPairif the flagAUTOSCALING_GENERATE_LAUNCH_TEMPLATEis disabledChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license