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

(aws-autoscaling): Missing KeyPair field on autoScalingGroupProps #29237

Closed
Brads3290 opened this issue Feb 23, 2024 · 2 comments · Fixed by #29679
Closed

(aws-autoscaling): Missing KeyPair field on autoScalingGroupProps #29237

Brads3290 opened this issue Feb 23, 2024 · 2 comments · Fixed by #29679
Labels
@aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@Brads3290
Copy link

Describe the bug

Using the KeyName to specify a key pair will be deprecated on the launchTemplateProps construct.

When using KeyName on autoScalingGroupProps, CDK gives the following warning on synth:

[WARNING] aws-cdk-lib.aws_ec2.LaunchTemplateProps#keyName is 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
  This API will be removed in the next major release.

Presumably autoScalingGroupProps uses launchTemplateProps underneath. autoScalingGroupProps should have a KeyPair property that is passed to the underlying launchTemplateProps.

Expected Behavior

autoScalingGroupProps should have a KeyPair property that is passed to the underlying launchTemplateProps.

Current Behavior

[WARNING] aws-cdk-lib.aws_ec2.LaunchTemplateProps#keyName is 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
  This API will be removed in the next major release.

Reproduction Steps

var asg = new AutoScalingGroup(this, "Asg", new AutoScalingGroupProps() {
    Vpc = props.Vpc,
    VpcSubnets = new SubnetSelection() {
        AvailabilityZones = props.AvailabilityZone is not null
            ? new[] { props.AvailabilityZone }
            : null,
    },
    InstanceType = InstanceType.Of(InstanceClass.T3A, InstanceSize.MEDIUM),
    MachineImage = EcsOptimizedImage.AmazonLinux2023(),
    SecurityGroup = instanceSg,
    KeyName = props.Ec2KeyPair, // <-- This
});

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.129.0 (build d5ab0df)

Framework Version

No response

Node.js Version

v18.16.1

OS

MacOS

Language

.NET

Language Version

No response

Other information

No response

@Brads3290 Brads3290 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 23, 2024
@github-actions github-actions bot added the @aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling label Feb 23, 2024
@pahud
Copy link
Contributor

pahud commented Feb 26, 2024

Yes, as AutoScaling is using LaunchTemplate L2 to create the launch template when feature flag is enabled:

I think we should follow the convention as here

keyName: props.keyPair?.keyPairName ?? props?.keyName,

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2024
@mergify mergify bot closed this as completed in #29679 May 10, 2024
mergify bot pushed a commit that referenced this issue May 10, 2024
### 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 the `keyName` will be removed

This configuration allows sending the `keyPair` to the asg since the LaunchTemplate allows its integration

Warning:
> [WARNING] aws-cdk-lib.aws_ec2.LaunchTemplateProps#keyName is deprecated.

Closes #29237

### Reason for this change

I'm working directly with CDK and needed to implement a way to use my `keyPair` and avoid warning that `keyName` will be removed soon when i'm creating my ASG

### Description of changes

- Add `keyPair` to CommonAutoScalingGroupProps interface
- Prevent `keyPair` and `keyName` from being set at the same time
- Send `keyPair` when creating LaunchTemplate if flag `AUTOSCALING_GENERATE_LAUNCH_TEMPLATE` is enabled
- Prevent `keyPair` if the flag `AUTOSCALING_GENERATE_LAUNCH_TEMPLATE` is disabled


### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

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

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants