aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
166 stars 55 forks source link

Handle CDK version mismatch #2018

Closed sobolk closed 1 week ago

sobolk commented 1 week ago

Problem

When installed aws-cdk and aws-cdk-lib are not compatible a fault is raised.

Repro.

Create project like and use mismatched CDK versions.

{
  "name": "testapp048",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@aws-amplify/backend": "^1.2.1",
    "@aws-amplify/backend-cli": "^1.2.6",
    "aws-cdk": "2.130.0",
    "aws-cdk-lib": "2.158.0",
    "constructs": "^10.3.0",
    "esbuild": "^0.23.1",
    "tsx": "^4.19.1",
    "typescript": "^5.6.2"
  },
  "dependencies": {
    "aws-amplify": "^6.6.1"
  }
}

Observe image

Changes

Add mapping and classify as user error.

Validation

  1. Added test.
  2. Manual verification

image

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

changeset-bot[bot] commented 1 week ago

🦋 Changeset detected

Latest commit: a49a0064ed627ed80c136558c75ad88a0be9f755

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----------------------------- | ----- | | @aws-amplify/backend-deployer | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

sobolk commented 1 week ago

LGTM. One question, so the only way customers run into this is if they update their package.json? We would have to keep a close eye to make sure this isn't unintentionally changed to have mismatched versions

https://github.com/aws-amplify/amplify-backend/blob/5af7781d27f90518432d8140d3edae8a9136ade5/packages/create-amplify/src/amplify_project_creator.ts#L18-L19

The other way would be to surgically npm update aws-cdk-lib without the other one. I.e. they won't get into this situation by following our create flow. The mismatch happens after create flow, by playing with package.json or npm commands.

As for us changing create flow to mismatched versions. This one is tricky to assert because as long as we ^ both versions the npm will install both at latest - which in theory is correct state. We would grossly mess this up if we skip ^, but this would surface in e2e tests or canaries.