ImportError: cannot import name 'docevents' from 'botocore.docs.bcdoc' in AWS CodeBuild

ImportError: cannot import name 'docevents' from 'botocore.docs.bcdoc' in AWS CodeBuild

ImportError: 无法从 'botocore.docs.bcdoc'
导入名称 'docevents' (/python3.7/site-packages/botocore/docs/bcdoc/init.py)

Traceback (most recent call last):
  File "/root/.pyenv/versions/3.7.6/bin/aws", line 19, in <module>
    import awscli.clidriver

  File "/root/.pyenv/versions/3.7.6/lib/python3.7/site-packages/awscli/clidriver.py", line 36, in <module>
    from awscli.help import ProviderHelpCommand

  File "/root/.pyenv/versions/3.7.6/lib/python3.7/site-packages/awscli/help.py", line 23, in <module>
    from botocore.docs.bcdoc import docevents

ImportError: cannot import name 'docevents' from 'botocore.docs.bcdoc' (/root/.pyenv/versions/3.7.6/lib/python3.7/site-packages/botocore/docs/bcdoc/__init__.py)

[Container] 2020/10/29 16:48:39 Command did not exit successfully aws --version exit status 1

失败发生在PRE_BUILD

这是我的规范构建文件:buildspec-cd.yml

pre_build:
    commands:
      - AWS_REGION=${AWS_DEFAULT_REGION}
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_VERSION=${COMMIT_HASH}
      - REPOSITORY_URI=${CONTAINER_REGISTRY}/${APPLICATION_NAME}
      - aws --version
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)

代码构建工作正常,没有任何更改。 只是停止工作了。

阅读这篇文章 GitHub issue #2596. 我修正了我的错误。

就在 PRE_BUILD 部分之前,我将这一行添加到我的 buildspec-cd.yml 文件中:

pip3 安装 --upgrade awscli

install:
    commands:
      - pip3 install awsebcli --upgrade
      - eb --version
      - pip3 install --upgrade awscli

    pre_build:
      commands:
      - AWS_REGION=${AWS_DEFAULT_REGION}
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_VERSION=${COMMIT_HASH}
      ...

对我来说这是一个版本问题。所以,我用以下版本修复了它:

  1. aws-cli/1.18.105

命令:sudo python3 -m pip3 install awscli==1.18.105

  1. botocore/1.17.28

命令:sudo python3 -m pip3 install botocore==1.17.28

在 Ubuntu 20.04 上遇到同样的错误,@vijay rajput 的回答一开始没有用,通过将 pip3 替换为 pip - sudo python3 -m pip install awscli==1.18.105sudo python3 -m pip install botocore==1.17.28 来修复 感谢

pip 卸载 botocore 为我工作

我也在 Ubuntu 20.04 上遇到了这个错误(虽然不是在 CodeBuild 中,我是 运行 aws lambda invoke)。安装 AWS CLI v2 (https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html) 对我有用:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

在我的例子中,此错误发生在 运行 命令 'aws --version' ubuntu 20.04。

解决方案是:

python3 -m pip install –-upgrade pip
python3 -m pip uninstall awscli
python3 -m pip install awscli