简体   繁体   中英

How to solve CDK CLI version mismatch

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.

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

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

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.

nothing helps for mac OS except this command:

yarn global upgrade aws-cdk@latest

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

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.

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 

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"
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM