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_ec2: ipAddresses is an invalid key for Python, but CIDR gives deprecation warning to use it #30510

Closed
andrewvaughan opened this issue Jun 10, 2024 · 4 comments
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@andrewvaughan
Copy link

andrewvaughan commented Jun 10, 2024

Describe the bug

The VPC.cidr prop is deprecated to be removed in the next major release. The deprecation notice and documentation state to use ipAddresses, instead.

If you use ipAddresses in Python, you get an Exception:

TypeError: Vpc.__init__() got an unexpected keyword argument 'ipAddresses'

Expected Behavior

Replacing the cidr prop for a VPC with an ipAddresses prop, as directed by the deprecation warning, should succeed.

Current Behavior

Traceback (most recent call last):
  File "/Users/andrew/Repositories/REDACTED/devops/infra/entrypoint.py", line 10, in <module>
    NetworkingVPC(app, "vpc-common")
  File "/Users/andrew/.pyenv/versions/3.12.0/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/andrew/Repositories/REDACTED/devops/infra/Networking/VPC.py", line 20, in __init__
    vpc = aws_ec2.Vpc(
          ^^^^^^^^^^^^
  File "/Users/andrew/.pyenv/versions/3.12.0/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Vpc.__init__() got an unexpected keyword argument 'ipAddresses'

Subprocess exited with error 1

Reproduction Steps

vpc = aws_ec2.Vpc(
    self,
    "vpc-common",
    max_azs=1,
    # cidr="10.0.0.0/16", # This shows a "Deprecated" warning
    ipAddresses=aws_ec2.IpAddresses.cidr(
        "10.0.0.0/16"
    ) # This raises a `TypeError` Exception
)

Possible Solution

Add the ipAddresses as a valid keyword for Python.

Additional Information/Context

No response

CDK CLI Version

2.145.0 (build fdf53ba)

Framework Version

No response

Node.js Version

v22.2.0

OS

macOS

Language

Python

Language Version

Python 3.12.0

Other information

No response

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

This may be a confusion with the way deprecation warnings are currently performed in Python.

ip_addresses is the valid property, but the warning still explicitly states the TypeScript variable. This isn't immediately clear unless you just happen to know to "Pythonize" things with CDK:

[WARNING] aws-cdk-lib.aws_ec2.VpcProps#cidr is deprecated.
  Use ipAddresses instead
  This API will be removed in the next major release.

@ashishdhingra ashishdhingra self-assigned this Jun 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 Jun 10, 2024
@ashishdhingra
Copy link
Contributor

@andrewvaughan Good morning. Thanks for reporting the issue. You are right, ip_addresses is a valid property. So the following code works:

from aws_cdk import (
    # Duration,
    Stack,
    aws_ec2 as ec2,
)
from constructs import Construct

class PythonStack(Stack):

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

        vpc = ec2.Vpc(self, 
                      "vpc-common",
                      ip_addresses=ec2.IpAddresses.cidr("10.0.0.0/16")
                      )

Refer Python Vpc documentation.

Regarding the warning message, the Python code is converted to TypeScript code via JSII layer and then the CFN template is synthesized from converted TypeScript code. The warning message is thrown in the converted TypeScript code.

Please let us know if you are unblocked and is this issue could be closed.

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-reproduction This issue needs reproduction. labels Jun 13, 2024
@ashishdhingra ashishdhingra closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
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.

@andrewvaughan
Copy link
Author

Thank you for the detailed response! You nailed it exactly. Even if the documentation can't be updated, this issue will likely help people Googling for the issue like I was. Cheers!

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. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants