简体   繁体   中英

Installing AWS CDK on Amazon Linux 2

According to the instructions here , it should be possible to install the CDK package for Python development within CloudFormation.

I'm using a t2.micro Amazon Linux 2: ami-0dd555eb7eb3b7c82 in eu-west-2 just for completeness.

The instructions state to run this: python -m pip install aws-cdk-lib This fails with "/usr/bin/python: No module named pip" , but replacing python with python3 resolves the issue and the installation completes with this message:

Installing collected packages: attrs, typing-extensions, cattrs, six, python-dateutil, jsii, publication, constructs, aws-cdk-lib
Successfully installed attrs-21.4.0 aws-cdk-lib-2.13.0 cattrs-1.10.0 constructs-10.0.69 jsii-1.54.0 publication-0.0.3 python-dateutil-2.8.2 six-1.16.0 typing-extensions-4.1.1

Further to that, when doing >>>help('modules') in the python3 interpreter now shows aws_cdk - so from that I'm assuming that all is good !!

The instructions indicate that the next step is to run python using the import - so I've created this:

#!/usr/bin/python3

import aws_cdk
print('hello')

However, running this returns alot of error messages. I've proceeded to look at the files mentioned and to try to figure out what I'm doing wrong but I've hit a dead end. I wonder if anybody has any ideas?

Traceback (most recent call last):
  File "/usr/lib64/python3.7/importlib/resources.py", line 188, in path
    yield Path(reader.resource_path(resource))
  File "/usr/local/lib/python3.7/site-packages/jsii/_runtime.py", line 43, in load
    _kernel.load(assembly.name, assembly.version, os.fspath(assembly_path))
  File "/usr/local/lib/python3.7/site-packages/jsii/_kernel/__init__.py", line 269, in load
    self.provider.load(LoadRequest(name=name, version=version, tarball=tarball))
  File "/usr/local/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 338, in load
    return self._process.send(request, LoadResponse)
  File "/usr/local/lib/python3.7/site-packages/jsii/_utils.py", line 24, in wrapped
    stored.append(fgetter(self))
  File "/usr/local/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 333, in _process
    process.start()
  File "/usr/local/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 259, in start
    env=environ,
  File "/usr/lib64/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/usr/lib64/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'node': 'node'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./l", line 3, in <module>
    import aws_cdk
  File "/usr/local/lib/python3.7/site-packages/aws_cdk/__init__.py", line 1051, in <module>
    from ._jsii import *
  File "/usr/local/lib/python3.7/site-packages/aws_cdk/_jsii/__init__.py", line 11, in <module>
    import constructs._jsii
  File "/usr/local/lib/python3.7/site-packages/constructs/__init__.py", line 41, in <module>
    from ._jsii import *
  File "/usr/local/lib/python3.7/site-packages/constructs/_jsii/__init__.py", line 12, in <module>
    "constructs", "10.0.69", __name__[0:-6], "constructs@10.0.69.jsii.tgz"
  File "/usr/local/lib/python3.7/site-packages/jsii/_runtime.py", line 43, in load
    _kernel.load(assembly.name, assembly.version, os.fspath(assembly_path))
  File "/usr/lib64/python3.7/contextlib.py", line 161, in __exit__
    raise RuntimeError("generator didn't stop after throw()")
RuntimeError: generator didn't stop after throw()
Exception ignored in: <function _NodeProcess.__del__ at 0x7f3fc99ebb90>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 224, in __del__
    self.stop()
  File "/usr/local/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 281, in stop
    if not self._process.stdin.closed:
AttributeError: '_NodeProcess' object has no attribute '_process'

I also have a "home machine" running Centos and get very similar messages. However, I proceeded with an ec2 instance to make the problem more easily replicable and documentable. Thankyou.

As stated on the linked page, you should first install the AWS CDK, which is done with npm . Which is the node.js package manager; the latter is very likely the 'node' referred to in the error message, since it is an external (executable) file that is run through subprocess .

So install node and npm first (they probably come together), then proceed with install the Python AWS CDK.

Thankyou "9769953" - the answer appears to be that for AWS CDK python library to work you have to install the dependencies for node.

This article has also helped.

For documentation - here is the method to install AWS CDK for python on Amazon Linux 2 - and other similar Linux distros.

a. Install Node Version manager.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

b. Activate nvm.

. ~/.nvm/nvm.sh

c. Install node.

nvm install node

d. Check versions (optional).

node -v
npm -v

e. Finally the python bit !

python3 -m pip install aws-cdk-lib

f. Run a Python program.

#!/usr/bin/python3
import aws_cdk
print('hello')

That's it.

Thankyou again to "9769953" and also to "CyberEternal".

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