fix(ec2): passing keypair to instance unexpectedly does nothing#28482
fix(ec2): passing keypair to instance unexpectedly does nothing#28482mergify[bot] merged 10 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.
|
|
|
@ayush-shah-1501 this PR title should be |
|
@ayush-shah-1501 Thanks for catching this! So sorry for missing this in the original PR. I will momentarily open a PR on your repo that will add a possible test & updates the integration tests. Additionally, so long as a user follows the docs for how to use an existing key pair, this should not be a breaking change. Edit: Hopefully ayush-shah-1501#1 can help address some of the linter concerns. But it may be good to ask for an Exemption Request if the linter is still mad about the integration test. |
Add additional tests for EC2 Instance Key Pair
|
Exemption Request: This PR is quick fix of #28138 PR |
|
For what it's worth, I think it's safe to not call this a breaking change. The correct behavior is documented and it does work correctly for other resource types; this condition was just missed in the implementation for |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
|
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). |
|
I am not sure if this change is at fault here, but using the ´keyPair´ parameter does not set the Ref in CFN. It does nothing. Example: key_pair = aws_ec2.KeyPair(
self,
f"Keypair",
public_key_material="some key",
)
instance = aws_ec2.Instance(
self,
f"id",
vpc=base.vpc,
instance_type=aws_ec2.InstanceType.of(
aws_ec2.InstanceClass.T3, aws_ec2.InstanceSize.MICRO
),
machine_image=aws_ec2.MachineImage.generic_linux(
{'eu-central-1': 'ami-0faab6bdbac9486fb'}
),
key_pair=key_pair,
# key_name=key_pair.key_pair_name,
associate_public_ip_address=True,
vpc_subnets=aws_ec2.SubnetSelection(
subnet_type=aws_ec2.SubnetType.PUBLIC
),
)
|
|
@cponfick this hasn't been released yet. will be out in 2.119.0, which will probably go out today. let us know in a new issue if the problem persists! |
|
I'm using a slightly higher version 2.121.1 and it's working fine for me. Thank you for the contribution! |
|
Has this been regressed? I just used |
Fixes by Specifying key pair reference in cfnInstance.
This will change behavior if both
keyNameandkeyPairis set on an existing resource, since we will usekeyPair.keyPairNameinstead ofkeyNamenow. However, there is no correct use case for specifying bothkeyPairandkeyName, and givenkeyNameis deprecated, this PR is introducing the correct behavior.Closes #28478.
Closes #28569
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license