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

ec2: "[WARNING] aws-cdk-lib.aws_ec2.InstanceProps#keyName is deprecated" appears when there are no references to keyName in the stack #30806

Open
paulgear opened this issue Jul 9, 2024 · 2 comments
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@paulgear
Copy link

paulgear commented Jul 9, 2024

Describe the bug

When building a VPC stack, the following deprecation warning appears:

[WARNING] aws-cdk-lib.aws_ec2.InstanceProps#keyName is deprecated.

The stack does not reference any EC2 instance or InstanceProps or keyName or keyPair directly. I think this is coming from a call to aws_ec2.NatProvider.instance_v2, but I can't be certain because there appears to be no reference to keyName or key_name in that module, nor can I find any evidence that there is a default value for keyName.

Expected Behavior

  1. We should not get deprecation warnings for features we aren't using.
  2. We should get deprecation warnings with more context so that we can log more accurate bug reports.

Current Behavior

When building a VPC stack, the following deprecation warning appears:

[WARNING] aws-cdk-lib.aws_ec2.InstanceProps#keyName is deprecated.

Reproduction Steps

I'll attempt to provide one of these at a later time.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.148.0 (build e5740c0)

Framework Version

No response

Node.js Version

v18.20.3

OS

Linux (Ubuntu 24.04 LTS in docker)

Language

Python

Language Version

3.12.3

Other information

No response

@paulgear paulgear added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 9, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jul 9, 2024
@paulgear
Copy link
Author

Here is a minimal reproducer stack:

import aws_cdk as cdk

from constructs import Construct

class TestStack(cdk.Stack):
  def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
    super().__init__(scope, construct_id, **kwargs)

    nat_gateway_provider = cdk.aws_ec2.NatProvider.instance_v2(
        instance_type=cdk.aws_ec2.InstanceType.of(
            instance_class=cdk.aws_ec2.InstanceClass.BURSTABLE3_AMD,
            instance_size=cdk.aws_ec2.InstanceSize.MICRO,
        ),
        # Disable default incoming allow all ingress
        default_allowed_traffic=cdk.aws_ec2.NatTrafficDirection.OUTBOUND_ONLY,
    )
    self.vpc = cdk.aws_ec2.Vpc(
        self,
        "testvpc",
        ip_addresses=cdk.aws_ec2.IpAddresses.cidr("10.1.0.0/16"),
        max_azs=1,
        nat_gateway_provider=nat_gateway_provider,
        subnet_configuration=[
            cdk.aws_ec2.SubnetConfiguration(
                name="public",
                subnet_type=cdk.aws_ec2.SubnetType.PUBLIC,
                cidr_mask=24,
            ),
            cdk.aws_ec2.SubnetConfiguration(
                name="private",
                subnet_type=cdk.aws_ec2.SubnetType.PRIVATE_WITH_EGRESS,
                cidr_mask=24,
            ),
        ],
    )

@ashishdhingra ashishdhingra self-assigned this Jul 10, 2024
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 10, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Jul 10, 2024

Reproducible using below TypeScript CDK code:

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

export class Issue30806Stack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const natGatewayProvider = ec2.NatProvider.instanceV2({
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3_AMD, ec2.InstanceSize.MICRO),
      defaultAllowedTraffic: ec2.NatTrafficDirection.OUTBOUND_ONLY
    });

    const vpc = new ec2.Vpc(this, 'testvpc', {
      ipAddresses: ec2.IpAddresses.cidr('10.1.0.0/16'),
      maxAzs: 1,
      natGatewayProvider: natGatewayProvider,
      subnetConfiguration: [
        {
          name: 'public',
          subnetType: ec2.SubnetType.PUBLIC,
          cidrMask: 24
        },
        {
          name: 'private',
          subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS,
          cidrMask: 24
        }
      ]
    });
  }
}

Running cdk synth prints the below deprecation warning at the beginning:

[WARNING] aws-cdk-lib.aws_ec2.InstanceProps#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.

Initial Analysis:

@ashishdhingra ashishdhingra added p2 effort/small Small work item – less than a day of effort and removed needs-reproduction This issue needs reproduction. labels Jul 10, 2024
@ashishdhingra ashishdhingra removed their assignment Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants