aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.8k stars 820 forks source link

JavaScript error when importing into python CDK stack #12447

Open maBarabas opened 2 years ago

maBarabas commented 2 years ago

When I try to import an Amplify app into a CDK stack defined in python I get the following error after cdk synth. The same amplify app imported into a JavaScript CDK stack works.

$ node --version
v16.13.2

$ cdk --version
2.8.0 (build 8a5eb49)

    # python dependencies setup
    install_requires=[
        "aws-amplify.cdk.exported-backend==0.0.5",
        "aws-cdk.core==1.137.0",
        "aws-cdk.aws-lambda==1.137.0",
        "aws-cdk.aws-lambda-python==1.137.0",
        "aws-cdk.aws-amplify==1.137.0",
        "aws-cdk.aws-iam==1.137.0",
    ],

    # JavaScript dependencies setup
  "dependencies": {
    "@aws-amplify/cdk-exported-backend": "^0.0.5",
    "@aws-cdk/core": "1.137.0",
    "@aws-cdk/aws-lambda": "1.137.0",
    "@aws-cdk/aws-lambda-python": "1.137.0",
    "@aws-cdk/aws-amplify": "1.137.0",
    "@aws-cdk/aws-iam": "1.137.0",
    "source-map-support": "^0.5.16"
  }
jsii.errors.JavaScriptError:
  node:internal/modules/cjs/loader:936
    throw err;
    ^

  Error: Cannot find module 'lodash'
  Require stack:
  - /tmp/jsii-kernel-7PvqTu/node_modules/@aws-amplify/cdk-exported-backend/lib/export-backend-asset-handler/index.js
  - /tmp/jsii-kernel-7PvqTu/node_modules/@aws-amplify/cdk-exported-backend/lib/export-backend.js
  - /tmp/jsii-kernel-7PvqTu/node_modules/@aws-amplify/cdk-exported-backend/lib/index.js
  - 2742
      at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
      at Function.Module._load (node:internal/modules/cjs/loader:778:27)
      at Module.require (node:internal/modules/cjs/loader:1005:19)
      at require (node:internal/modules/cjs/helpers:102:18)
      at Object.<anonymous> (/tmp/jsii-kernel-7PvqTu/node_modules/@aws-amplify/cdk-exported-backend/lib/export-backend-asset-handler/index.js:10:11)
      at Module._compile (node:internal/modules/cjs/loader:1101:14)
      at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
      at Module.load (node:internal/modules/cjs/loader:981:32)
      at Function.Module._load (node:internal/modules/cjs/loader:822:12)
      at Module.require (node:internal/modules/cjs/loader:1005:19)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "app.py", line 12, in <module>
    from cdk_amplify_import_test.cdk_amplify_import_test_stack import CdkAmplifyImportTestStack
  File "/home/barabas/esp/cdk-amplify-import-test/cdk_amplify_import_test/cdk_amplify_import_test_stack.py", line 2, in <module>
    from aws_amplify.cdk.exported_backend import AmplifyExportedBackend
  File "/home/barabas/esp/cdk-amplify-import-test/.venv/lib/python3.8/site-packages/aws_amplify/cdk/exported_backend/__init__.py", line 74, in <module>
    from ._jsii import *
  File "/home/barabas/esp/cdk-amplify-import-test/.venv/lib/python3.8/site-packages/aws_amplify/cdk/exported_backend/_jsii/__init__.py", line 23, in <module>
    __jsii_assembly__ = jsii.JSIIAssembly.load(
  File "/home/barabas/esp/cdk-amplify-import-test/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 43, in load
    _kernel.load(assembly.name, assembly.version, os.fspath(assembly_path))
  File "/home/barabas/esp/cdk-amplify-import-test/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 269, in load
    self.provider.load(LoadRequest(name=name, version=version, tarball=tarball))
  File "/home/barabas/esp/cdk-amplify-import-test/.venv/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 338, in load
    return self._process.send(request, LoadResponse)
  File "/home/barabas/esp/cdk-amplify-import-test/.venv/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 326, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Cannot find module 'lodash'
Require stack:
- /tmp/jsii-kernel-7PvqTu/node_modules/@aws-amplify/cdk-exported-backend/lib/export-backend-asset-handler/index.js
- /tmp/jsii-kernel-7PvqTu/node_modules/@aws-amplify/cdk-exported-backend/lib/export-backend.js
- /tmp/jsii-kernel-7PvqTu/node_modules/@aws-amplify/cdk-exported-backend/lib/index.js
- 2742
maBarabas commented 2 years ago

pip freeze

$ python --version
Python 3.8.10

$ python -m pip --version
pip 22.0.3 from /home/barabas/esp/cdk-amplify-import-test/.venv/lib/python3.8/site-packages/pip (python 3.8)
github-actions[bot] commented 2 years ago

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

csotomon commented 1 year ago

i am having the same issue, any update about this bug?

Cli: aws-cdk 2.72.1

Python packages: aws-amplify.cdk.exported-backend==0.0.6 aws-cdk-lib==2.72.1 constructs>=10.0.0,<11.0.0

martonjuhasz98 commented 8 months ago

I'm having the same issue still. Is there an expected time to fix this?

CLI: aws-cdk 2.99.1

requirements.txt aws-amplify.cdk.exported-backend==0.0.6 aws-cdk-lib==2.97.0