Instructions: How to upgrade AWS CDK
Why?
Because AWS CDK is still a work in progress, and if you don’t keep it up to date, you’ll end up doing a major version upgrade, and won’t be able to recover your projects.
How?
Quite simple actually, if you don’t forget any of the steps.
Step 1: Deactivate the Virtual Environment
(.env) ➜ iac git:(dev) ✗ deactivate
➜ iac git:(dev) ✗
Step 2: Upgrade CDK
NPM doesn’t really have an upgrade command like YUM, so you need to “install again”. You might also want to keep your npm upgraded… just in case. You probably need to sudo
:
npm install -g npm
npm install -g aws-cdk
Make sure the upgrade went well:
➜ iac git:(dev) ✗ cdk --version
**1.37.0 (build e4709de)**
You should be seeing something like this:
And what the bottom line needs to look like:
Successfully installed aws-cdk.cloud-assembly-schema-1.37.0 aws-cdk.core-1.37.0 aws-cdk.cx-api-1.37.0
Step 3: Super important: Upgrade CDK CORE library
pip install --upgrade aws-cdk.core
This might give you a requirement issue because your requirements.txt
file still has the old versions as requirements. There’s probably a more elegant solution for this, but I actually go to the requirements.txt and replace dependencies to the new version. From what I’ve been seeing in the Git repo, the versions are maintained coherent, so this should not present any problems.
Verification
Remember to do this, as it sometimes happens that not all libraries were upgraded correctly.
Go to your project, and file by file, Find - “1.36.", or whichever your previous version of cdk was. I know, it’s a hustle… but trust me, you do need to mitigate this risk. If you catch a 1.36
somewhere - be sure to change it to 1.37.0, and upgrade and freeze your requirements.
pip install -r requirements.txt
pip freeze > requirements.txt
Now get to your virtual environment again, and make sure cdk deploy
works, before you start changing the code, and blaming my blog cause something went wrong:
That’s all. If I missed something, let me know in the comments.