AWS's Elastic Beanstalk not using my virtualenv: “No module named boto”

前端 未结 2 635
忘掉有多难
忘掉有多难 2021-01-25 00:33

I\'m trying to use AWS\'s Elastic Beanstalk, but when I run eb start, I get \"ImportError: No module named boto Cannot run aws.push for local repository HEAD.\"

2条回答
  •  时光说笑
    2021-01-25 01:35

    I had a similar problem using eb push. The issue is that eb uses git during the process to push the contents to AWS (git aws.push). You can find the scripts inside ".git/AWSDevTools/" on your repository dir.

    When git runs it modifies the environment variable $PATH and appends "/usr/libexec/git-core:/usr/bin" to the beginning of $PATH. This makes the AWS scripts to use /usr/bin/python instead of the python on the virtualenv, which doesn't have boto installed.

    I fixed this by adding a wrapper on top of the AWS scripts that verifies if there is a virtualenv enabled and corrects the $PATH variable.

    .git/AWSDevTools/pre.aws.elasticbeanstalk.push

    #!/bin/bash
    
    if [ -n $VIRTUAL_ENV ]; then
        PATH=$VIRTUAL_ENV/bin:$PATH
    fi
    
    DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
    python $DIR/aws.elasticbeanstalk.push
    

    And then modified the .git/config file to make the aws.push alias call the wrapper

    [alias "pre.aws.elasticbeanstalk"]  
        push = !.git/AWSDevTools/pre.aws.elasticbeanstalk.push
    
    [alias "aws"]
        push = !git pre.aws.elasticbeanstalk.push  #Modified this line to call the wrapper
    

提交回复
热议问题