Python cfn_tools 模块不会在 AWS CodePipeline 的 AWS CodeBuild 运行 中加载

Python cfn_tools module won't load in AWS CodeBuild running in AWS CodePipeline

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

有趣的是,我第一次通过 CodeBuild 使用此模块 运行 时没有遇到任何问题。它只是在我进行下一个 gitHub 推送后才开始发生,该推送启动了我的管道,我看到了这个。与此相关的文件没有更改,下一次推送中的修改是对 repo 的不相关部分。

此后我尝试这样做:

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

更新: 为了添加更多信息,我从 S3 下载了一个 .tar.gz 文件,其中包含在此构建中 运行ning 所需的 python 脚本。我提取 .tar.gz 然后我 运行 有错误的脚本。 这是我安装 cfn-tools 并执行 pip freeze 时的输出 您将在下面看到 cfn-tools 加载并且是 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 没有安装它,所以它在第一个 运行 上的工作方式仍然是个谜。

This Whosebug question helped