Skip to content

aws_ec2: passing keyPair to Instance does nothing #28478

@SamuraiPrinciple

Description

@SamuraiPrinciple

Describe the bug

With keyName property being deprecated (#28138), creating aws_ec2.KeyPair and passing it to aws_ec2.Instance does nothing.

Expected Behavior

Make sure the keypair is associated with the instance when passed through keyPair property.

Current Behavior

keypair does not get associated with the instance.

Reproduction Steps

const keyPair = new ec2.KeyPair(this, 'KeyPair', {});
 this.instance = new ec2.Instance(this, 'EC2Instance', {
      vpc: props.vpc,
      vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },
      securityGroup,
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MICRO),
      machineImage: ec2.MachineImage.latestAmazonLinux2023(),
      keyPair,
      userDataCausesReplacement: true,
      ssmSessionPermissions: true,
    });

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.116.1 (build 222de71)

Framework Version

No response

Node.js Version

20.10.0

OS

Linux

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ec2Related to Amazon Elastic Compute CloudbugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions