Search code examples
python-3.xaws-lambdazappapython-zappa

New branch/stage using Zappa


I currently have an API up on AWS Lambda using Zappa/Flask (Py 3.7)

My zappa_Settings.json file looks like so:

{
    "beta": {
        "app_function": "application.application",
        "profile_name": "changed",
        "project_name": "changed",
        "runtime": "python3.7",
        "s3_bucket": "zappa-<obscured>"
    }

}

However, we are now working on a new set of features and sense dictates we have a separate branch or stage, like 'testing' where we deploy these and evaluate for maturity before pushing to the live environment.

The problem is, try as I might, I am unable to create a new stage from the console:

zappa init 

crashes with

click.exceptions.ClickException: This project already has a zappa_settings.json file!

zappa init stage2

produces

usage: zappa [-h] [-v] [--color {auto,never,always}] {certify,deploy,init,package,template,invoke,manage,rollback,schedule,status,tail,undeploy,unschedule,update,shell} ... zappa: error: unrecognized arguments: stage2

zappa deploy stage2

outputs

(botocore 1.12.86 (/home/user/Code/Python/project/lib/python3.6/site-packages), Requirement.parse('botocore<1.11.0,>=1.10.82'), {'boto3'})
Calling deploy for stage stage2..
Error: Please define stage 'stage2' in your Zappa settings.

Now, if I manually create an entry for a stage, I need to have an s3 bucket for the deployment. Is it safe to reuse the same one from the first instance? What do I do here to deploy a new stage?


Solution

  • zappa init is just to get you started with the zappa_settings.json file, you don't need to run this each time to edit it.

    for example.

    {
        "beta": {
            "app_function": "application.application",
            "profile_name": "changed",
            "project_name": "changed",
            "runtime": "python3.7",
            "s3_bucket": "zappa-<obscured>"
        },
        "stage2": {
            "app_function": "application.application",
            "profile_name": "changed",
            "project_name": "changed",
            "runtime": "python3.7",
            "s3_bucket": "zappa-<obscured>"
        }
    }
    

    however this could be better written as.

    {
        "common": {
            "app_function": "application.application",
            "profile_name": "changed",
            "project_name": "changed",
            "runtime": "python3.7",
            "s3_bucket": "zappa-<obscured>"
        },
        "beta": {
            "extends": "common"
            // additional overrides here
        },
        "stage2": {
            "extends": "common"
            // additional overrides here
        }
    }