Python cfn_tools 模块无法在 AWS CodePipeline 中运行的 AWS CodeBuild 中加载



我在执行CodeBuild时遇到以下错误:ModuleNotFoundError: No module named 'cfn_tools'

有趣的是,当我第一次用这个模块通过CodeBuild运行这个时,我没有遇到任何问题。直到我进行下一次gitHub推送,启动了我的管道后,我才看到了这一点。与此相关的文件没有更改,下一次推送中的修改是针对回购的一个不相关部分。

从那以后,我试着做:

  • pip install cfn-tools&pip3 install cfn-tools,其中提到模块已经安装。这些已添加到BuildSpec部分。没有成功-仍然有错误
  • 我添加了一个requirements.txt文件,但没有成功,仍然有错误。我也在BuildSpec中使用pip freeze创建了这个文件。模块显示,但仍然得到错误
  • 最初使用python的运行时版本3.7,然后尝试使用3.9,但仍然不起作用

python运行时3.9如有任何协助,我们将不胜感激。

更新:为了添加更多信息,我从S3下载了一个.tar.gz文件,其中包含在该构建中运行所需的python脚本。我提取.tar.gz,然后运行出现错误的脚本。以下是我安装cfn工具并执行pip冻结时的输出您将在下面看到,cfn工具加载并且是pip-freeze输出的一部分,但当我运行脚本时,它会给我上面的错误。

[Container] 2021/12/18 20:02:33 Running command pip3 install cfn-tools
Collecting cfn-tools
Downloading cfn-tools-0.1.6.tar.gz (3.9 kB)
Requirement already satisfied: Click>=6.0 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from cfn-tools) (7.1.2)
Requirement already satisfied: boto3>=1.3.1 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from cfn-tools) (1.18.58)
Requirement already satisfied: s3transfer<0.6.0,>=0.5.0 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from boto3>=1.3.1->cfn-tools) (0.5.0)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from boto3>=1.3.1->cfn-tools) (0.10.0)
Requirement already satisfied: botocore<1.22.0,>=1.21.58 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from boto3>=1.3.1->cfn-tools) (1.21.58)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from botocore<1.22.0,>=1.21.58->boto3>=1.3.1->cfn-tools) (2.8.2)
Requirement already satisfied: urllib3<1.27,>=1.25.4 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from botocore<1.22.0,>=1.21.58->boto3>=1.3.1->cfn-tools) (1.26.7)
Requirement already satisfied: six>=1.5 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.22.0,>=1.21.58->boto3>=1.3.1->cfn-tools) (1.16.0)
Building wheels for collected packages: cfn-tools
Building wheel for cfn-tools (setup.py): started
Building wheel for cfn-tools (setup.py): finished with status 'done'
Created wheel for cfn-tools: filename=cfn_tools-0.1.6-py3-none-any.whl size=5456 sha256=9cd3471445f6552165508b0bd797498a535d3ef264059c9739cc6b72f7b96a26
Stored in directory: /root/.cache/pip/wheels/51/1f/6f/f50a0600d46c29ca31519968efefdc4547e8cda7a756584837
Successfully built cfn-tools
Installing collected packages: cfn-tools
Successfully installed cfn-tools-0.1.6
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available.
You should consider upgrading via the '/root/.pyenv/versions/3.9.5/bin/python3.9 -m pip install --upgrade pip' command.
[Container] 2021/12/18 20:02:36 Running command pip3 freeze
arrow==1.2.0
attrs==21.2.0
aws-lambda-builders==1.8.1
aws-sam-cli==1.33.0
aws-sam-translator==1.39.0
awscli==1.20.58
backports.entry-points-selectable==1.1.0
binaryornot==0.4.4
boto3==1.18.58
botocore==1.21.58
certifi==2021.10.8
**cfn-tools==0.1.6**
chardet==4.0.0
chevron==0.14.0
click==7.1.2
colorama==0.4.3
cookiecutter==1.7.3
dateparser==1.1.0
distlib==0.3.3
docker==4.2.2
docutils==0.15.2
filelock==3.3.0
Flask==1.1.4
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.3
jinja2-time==0.2.0
jmespath==0.10.0
jsonschema==3.2.0
MarkupSafe==2.0.1
pipenv==2021.5.29
platformdirs==2.4.0
poyo==0.5.0
pyasn1==0.4.8
pyrsistent==0.18.0
python-dateutil==2.8.2
python-slugify==5.0.2
pytz==2021.3
PyYAML==5.4.1
regex==2021.10.8
requests==2.25.1
rsa==4.7.2
s3transfer==0.5.0
serverlessrepo==0.1.10
six==1.16.0
text-unidecode==1.3
tomlkit==0.7.2
tzlocal==3.0
urllib3==1.26.7
virtualenv==20.8.1
virtualenv-clone==0.5.7
watchdog==2.1.2
websocket-client==1.2.1
Werkzeug==1.0.1

我试图安装的模块不是正在使用的模块。

需要安装的模块是cfn_flip,它有代码试图使用的cfn_tools模块。CodeBuild没有安装它,所以它在第一次运行时是如何工作的仍然是个谜。

这个StackOverflow问题帮助

相关内容

  • 没有找到相关文章

最新更新