Zappa Update failing in CircleCI

Question:

I am trying to deploy my Python project to AWS Lambda using Zappa and circleci.

its throwing error Error: Zappa requires an active virtual environment!

#!/bin/bash -eo pipefail
zappa update dev
(PyYAML 3.13 (/usr/local/lib/python3.6/site-packages), Requirement.parse('PyYAML>=4.1'), {'cfn-flip'})
Calling update for stage dev..
Error: Zappa requires an active virtual environment!
Learn more about virtual environments here: http://docs.python-guide.org/en/latest/dev/virtualenvs/
Exited with code 1

I am installing venv using the below commands.

pip install virtualenv
virtualenv venv
source venv/bin/activate

Is there something that I am missing.
Could someone help me.

Asked By: Shamnad P S

||

Answers:

This is a short working example that uses python3 virtual env, not virtualenv package.
For it to work you need to set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as env vars in the CircleCI web UI.

version: 2
jobs:
  build:
    docker:
      - image: circleci/python:3.6.1

    working_directory: ~/app

    steps:
      - checkout

      - run:
          name: install dependencies
          command: |
            python3 -m venv ~/venv
            . ~/venv/bin/activate
            pip install -r requirements.txt

      - deploy:
          name: deploy
          command: |
            . ~/venv/bin/activate

            # set aws credentials
            mkdir -p ~/.aws
            echo -e "[default]" >> ~/.aws/credentials
            echo -e "aws_access_key_id = "$AWS_ACCESS_KEY_ID >> ~/.aws/credentials
            echo -e "aws_secret_access_key = "$AWS_SECRET_ACCESS_KEY >> ~/.aws/credentialstrouble

            # try to update, if the command fails do the initial deploy
            zappa update dev || zappa deploy dev;

Note that I’m using python 3.6.1 CircleCI image, I had some minor trouble with 3.6.9

Full example with dependencies caching, running test suite, testing if the package can be created, deployment to testing and production environment can be found here: https://github.com/mislavcimpersak/xkcd-excuse-generator/blob/master/.circleci/config.yml

Answered By: mislavcimpersak

I had to do install zappa , virtualenv using pip3 and then activate it.

sudo pip install zappa
sudo pip3 install virtualenv
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
zappa update dev
Answered By: Shamnad P S
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.