aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.62k stars 3.91k forks source link

(cli): Give a warning when the languages cdk libraries are older than cdk #19356

Open mrgum opened 2 years ago

mrgum commented 2 years ago

Description

Give a warning when the languages cdk libraries are older than cdk

Use Case

I spent hours trying to fix a circular dependency (in aws-cdk-lib.pipelines) I saw an issue with cdk 2.9.0 but thought I had 2.15.0 so it could not be that. Banged my head on the issue for ages then on a punt I ran pip install --upgrade -r requirements.txt and that fixed it.

Please could we have some warning when node's cdk and a language, like python's aws aws-cdk-lib, are out of step.

I know I could update the requirements.txt on each upgrade to version chase but that would be a pain

Proposed Solution

Warning: you are running cdk version 7.8.9 but your language support aws-cdk-lib is only version 1.2.3, consider upgrading

Other information

No response

Acknowledge

peterwoodworth commented 2 years ago

Thanks for the feature request @mrgum,

I'm not aware of any way to do this at the moment, so I think this would be pretty neat to have.

Should probably be opt-in, or if its on by default then make it easy to opt-out of only a single time.

mrgum commented 2 years ago

Something could also be added to the upgrade message

Currently

****************************************************
*** Newer version of CDK is available [2.16.0]   ***
*** Upgrade recommended (npm install -g aws-cdk) ***
****************************************************

Could be extended to

***********************************************************
*** Newer version of CDK is available [2.16.0]          ***
*** Upgrade recommended (npm install -g aws-cdk)        ***
*** If you are using a language, other than typescript, ***
*** we recommend you upgrade your aws-cdk libraries too ***
***********************************************************
mrgum commented 2 years ago

As for implementation, I think we could read in the app from cdk.json and regex if for python|.py -> python etc and run something like

from importlib.metadata import version 
if version('aws-cdk-lib') != "CDK_VERSION":
  "do something"

the detection of version might have to be language-specific?

mrgum commented 2 years ago

For now I've added this to my app and tested it by downgrading aws-cdk-lib

from importlib.metadata import version

cdk_cli_version = os.environ.get("CDK_CLI_VERSION")
cdk_lib_version = version("aws-cdk-lib")
assert cdk_cli_version == cdk_lib_version, f"local aws-cdk-lib is version {cdk_lib_version} where as cdk_cli is {cdk_cli_version}"

output

❯ cdk list
Traceback (most recent call last):
  File "/Users/prockter/yard/aws/cdk/version-check/app.py", line 12, in <module>
    assert cdk_cli_version == cdk_lib_version, f"local aws-cdk-lib is version {cdk_lib_version} where as cdk_cli is {cdk_cli_version}"
AssertionError: local aws-cdk-lib is version 2.15.0 where as cdk_cli is 2.16.0