Home > Enterprise >  Update project CDK packages at once
Update project CDK packages at once

Time:10-27

What could be a good approach to update all AWS CDK packages for a JavaScript/TypeScript project to a specific version at once?

I am looking for a suitable approach which I can use in CI/CD pipelines as well. I do not want to update or change other packages versions in my project.

CodePudding user response:

You can parse the package.json file in your pipeline and bump the cdk specific packages to a specific version number with a bash script.

Note that the core/resource specific AWS CDK packages start with @aws-cdk and the main AWS CDK package is named aws-cdk.

You can use the script like this: cdk-bump.sh 1.128.0

cdk-bump.sh

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "No CDK version provided!"
    exit 1
fi
GREEN='\033[0;32m'
NC='\033[0m'
tmp=$(mktemp)
for type in dependencies devDependencies; do
  for key in $(jq ".$type | keys[]" package.json); do
    if  [[ $key == \"@aws-cdk/* ]] || [[ $key == \"aws-cdk\" ]] ; then
      jq ".$type.$key = \"$1\"" package.json > "$tmp" && mv "$tmp" package.json
    fi
  done
done
npm install
echo -e "${GREEN}CDK package versions bumped to version $1${NC}"
  • Related