26

I'm getting following error:

This CDK CLI is not compatible with the CDK library used by your application. Please upgrade the CLI to the latest version. (Cloud assembly schema version mismatch: Maximum schema version supported is 8.0.0, but found 9.0.0)

after issuing cdk diff command.

I did run npm install -g aws-cdk@latest after which I've successfully installed new versions of packages: Successfully installed aws-cdk.assets-1.92.0 aws-cdk.aws-apigateway-1.92.0 aws-cdk.aws-apigatewayv2-1.92.0 ... etc. with pip install -r requirements.txt

However after typing cdk --version I'm still getting 1.85.0 (build 5f44668).

My part of setup.py is as follows:

    install_requires=[
    "aws-cdk.core==1.92.0",
    "aws-cdk.aws-ec2==1.92.0",
    "aws-cdk.aws_ecs==1.92.0",
    "aws-cdk.aws_elasticloadbalancingv2==1.92.0"
],

And I'm stuck now, as downgrading packages setup.py to 1.85.0 throwing ImportError: cannot import name 'CapacityProviderStrategy' from 'aws_cdk.aws_ecs'.

Help :), I would like to use newest packages version.

Maciej
  • 1,209
  • 4
  • 16
  • 26

10 Answers10

47

I encountered this issue with a typescript package, after upgrading the cdk in package.json. As Maciej noted upgrading did not seem to work. I am installing the cdk cli with npm, and an uninstall followed by an install fixed the issue.

npm -g uninstall aws-cdk
npm -g install aws-cdk
datascii
  • 571
  • 4
  • 3
  • I was spinning up a `go` project with `cdk 1.119.0`. This resolved the version error for me! – Kevin Wang Aug 25 '21 at 06:56
  • 1
    Ran into this issue after upgrading to the latest version in a NodeJS project with `npm install aws-cdk@latest`. Evidently you can't upgrade CDK, you have to remove it and reinstall it! – Malvineous Sep 14 '21 at 05:46
  • Even removing and reinstalling didn't work for me, I needed to remove the symlink as specified in @Maciej's answer (https://stackoverflow.com/a/66578813/2860309) – therightstuff Dec 17 '22 at 22:11
  • i was on AWS CDK CLI v2.23.0 and got "version supported is 19.0.0, but found 21.0.0" added the uninstall changed to `npm install -g aws-cdk@1.119.0` and got "13.00, but found 21.0.0" ------------------- changed to `npm install -g aws-cdk@1.158.0` and got "20.00, but found 21.0.0" ------------------- changed to `npm install -g aws-cdk@1.189.0` and it worked. – tkerwood Jan 24 '23 at 05:19
  • For me what worked was this ```npm -g uninstall cdk``` `npm -g uninstall cdk` not `aws-cdk` – Santanu Dey Mar 16 '23 at 08:19
7

nothing helps for mac OS except this command:

yarn global upgrade aws-cdk@latest

CloudA2Z
  • 99
  • 1
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 27 '21 at 15:35
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30682708) – l33tHax0r Dec 27 '21 at 16:56
  • 2
    I am not sure but this resolves my problem. – addicted Feb 03 '22 at 19:01
6

So I've fixed it, but is too chaotic to describe the steps.

It seems like there are problems with the symlink

/usr/local/bin/cdk

which was pointing to version 1.85.0 and not the one I updated to 1.92.0.

I removed the aws-cdk from the node_modules and installed it again, then removed the symlink /usr/local/bin/cdk and recreated it manually with

ln -s /usr/lib/node_modules/aws-cdk/bin/cdk /usr/local/bin/cdk
Onema
  • 7,331
  • 12
  • 66
  • 102
Maciej
  • 1,209
  • 4
  • 16
  • 26
3

For those coming here that are not using a global install (using cdk from node_modules) and using a mono-repo. This issue is due to the aws-cdk package of the devDependencies not matching the version of the dependencies for the package.

I was using "aws-cdk": "2.18.0" in my root package.json but all my packages were using "aws-cdk-lib": "2.32.1" as their dependencies. By updating the root package.json to use "aws-cdk": "2.31.1" this solved the issue.

Jeremy
  • 1,878
  • 2
  • 30
  • 54
2

I have been experiencing this a few times as well, so i am just dropping this solution which helps me resolves version mismatches, particularly on existing projects.

For Python:

What you need to do is modify the setup.py to specify the latest version.

Either, implicitly

    install_requires=[
    "aws-cdk.core",
    "aws-cdk.aws-ec2",
    "aws-cdk.aws_ecs",
    "aws-cdk.aws_elasticloadbalancingv2"
],

or explicitly;

    install_requires=[
    "aws-cdk.core==1.xx.x",
    "aws-cdk.aws-ec2==1.xx.x",
    "aws-cdk.aws_ecs==1.xx.x",
    "aws-cdk.aws_elasticloadbalancingv2==1.xx.x"
],

Then from project root, run;

setup.py install

For TypeScript:

Modify package.json;

"dependencies": {
    "@aws-cdk/core" : "latest",
    "source-map-support": "^0.5.16"
  }

Then run from project root:

npm install

I hope this helps! Please let me know if I need to elaborate or provide more details.

user2818782
  • 736
  • 8
  • 18
1

This worked for me in my dev environment since I had re-cloned the source, I needed to re-run the npm install command. A sample package.json might look like this (update the versions as needed):

{
    "dependencies": {
        "aws-cdk": "2.27.0",
        "node": "^16.14.0"
    }
}
Michael Behrens
  • 911
  • 10
  • 8
0

Uninstall the CDK version:

npm uninstall -g aws-cdk

Install specfic version which your application is using. For ex: CDK 1.158.0

npm install -g aws-cdk@1.158.0

horizon7
  • 1,113
  • 14
  • 18
0

If you've made it down here there are 2 options to overcome this issue.

  1. Provision a cloud9 env and run the code there.
  2. Run the app in a container.

Move the cdk app into a folder so that you have a parent folder to put a dockerfile a makefile and a dockercompose file.

fire up docker desktop cd into the root folder from the terminal and then run make

Dockerfile contents

FROM ubuntu:20.04 as compiler

WORKDIR /app/
RUN apt-get update -y \
    && apt install python3 -y \
    && apt install python3-pip -y \
    && apt install python3-venv -y \
    && python3 -m venv venv


ARG NODE_VERSION=16

RUN ls

RUN apt-get update
RUN apt-get install xz-utils
RUN apt-get -y install curl

RUN apt-get update -y && \
    apt-get upgrade -y && \
    apt-get install -y && \
    curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - && \
    apt install -y nodejs

RUN apt-get install -y python-is-python3
RUN npm install -g aws-cdk
RUN python -m venv /opt/venv

docker-compose.yaml contents

version: '3.6'
services:
  cdk-base:
    build: .
    image: cdk-base
    command: ${COMPOSE_COMMAND:-bash}
    volumes:
      - .:/app
      - /var/run/docker.sock:/var/run/docker.sock #Needed so a docker container can be run from inside a docker container
      - ~/.aws/:/root/.aws:ro

Makefile content

SHELL=/bin/bash
CDK_DIR=cdk_app/
COMPOSE_RUN = docker-compose run --rm cdk-base
COMPOSE_UP = docker-compose up
PROFILE = --profile default

all: pre-reqs synth
pre-reqs: _prep-cache container-build npm-install 
    

_prep-cache: #This resolves Error: EACCES: permission denied, open 'cdk.out/tree.json'
    mkdir -p cdk_websocket/cdk.out/

container-build: pre-reqs
    docker-compose build

container-info:
    ${COMPOSE_RUN} make _container-info

_container-info:
    ./containerInfo.sh

clear-cache:
    ${COMPOSE_RUN} rm -rf ${CDK_DIR}cdk.out && rm -rf ${CDK_DIR}node_modules

cli: _prep-cache
    docker-compose run cdk-base /bin/bash

npm-install: _prep-cache
    ${COMPOSE_RUN} make _npm-install

_npm-install:
    cd ${CDK_DIR} && ls && python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && npm -v && python --version

npm-update: _prep-cache
    ${COMPOSE_RUN} make _npm-update

_npm-update:
    cd ${CDK_DIR} && npm update

synth: _prep-cache
    ${COMPOSE_RUN} make _synth

_synth:
    cd ${CDK_DIR} && source .venv/bin/activate && pip install -r requirements.txt && cdk synth --no-staging ${PROFILE} && cdk deploy --require-approval never ${PROFILE}

bootstrap: _prep-cache
    ${COMPOSE_RUN} make _bootstrap

_bootstrap:
    cd ${CDK_DIR} && source .venv/bin/activate && pip install -r requirements.txt && cdk bootstrap ${PROFILE}

deploy: _prep-cache
    ${COMPOSE_RUN} make _deploy

_deploy: 
    cd ${CDK_DIR} && cdk deploy --require-approval never ${PROFILE}

destroy:
    ${COMPOSE_RUN} make _destroy

_destroy:
    cd ${CDK_DIR} && source .venv/bin/activate && pip install -r requirements.txt && cdk destroy --force ${PROFILE}

diff: _prep-cache
    ${COMPOSE_RUN} make _diff

_diff: _prep-cache
    cd ${CDK_DIR} && cdk diff ${PROFILE}

test: 
    ${COMPOSE_RUN} make _test

_test: 
    cd ${CDK_DIR} && npm test 
Leonardo Wildt
  • 2,529
  • 5
  • 27
  • 56
0

I changed typescript": "^4.7.3" version and it worked. Note: cdk version 2("aws-cdk-lib": "^2.55.0")

didar
  • 11
  • 1
0

I removed node_modules directory and it worked. I suppose you could simply remove only the cdk libs as well.