1

I have a flask_application which will do some simple task.

My Requirement: I want to deploy this flask_application as a aws lambda_function with the help of zappa

To run my flask_application as a lambda function, i am performing

  1. zappa init
  2. zappa package

and then i am uploading that zipped file into lambda and running my lambda function.

My Issue: when ever i run zappa init command, it is creating a zappa_setting.json file with some info like below

{
    "dev": {
        "app_function": "flask.main.app",
        "aws_region": "us-east-1",
        "profile_name": "dev",
        "project_name": "flask",
        "runtime": "python3.6",
        "s3_bucket": "zappa-p5m0kuurp"
    }
}

I have 3 aws environments and seperate buckets for each environment like

test  ==> zappa_test_bucket
stage ==> zappa_stage_bucket
prod  ==> zappa_prod_bucket

I want to deploy my flask application in all 3 aws environments by providing custom zappa_settings.json.

Question: Is there a way to provide zappa_settings.json as a file and then whenever i run zappa init, zappa will take this file as a input and set these environmental varible according to environment.

zappa_settings.json

{
    "test": {
        "app_function": "flask.main.app",
        "aws_region": "us-east-1",
        "profile_name": "dev",
        "project_name": "flask",
        "runtime": "python3.6",
        "s3_bucket": "zappa_test_bucket"
    },
        "stage": {
        "app_function": "flask.main.app",
        "aws_region": "us-east-1",
        "profile_name": "dev",
        "project_name": "flask",
        "runtime": "python3.6",
        "s3_bucket": "zappa_stage_bucket"
    },

    "prod": {
        "app_function": "flask.main.app",
        "aws_region": "us-east-1",
        "profile_name": "dev",
        "project_name": "flask",
        "runtime": "python3.6",
        "s3_bucket": "zappa_prod_bucket"
    }


}

if anyone have an idea, please let me know

1 Answer 1

3

What I understand is that you use zappa init each time you deploy the code. After that you upload your code to lambda manually.

You must rather use the functionalities of zappa to the fullest:

  • Use zappa init just once.
  • Update your zappa_settings.json file just once.
  • From now own, do your deployments with zappa deploy dev/stage/prod

See this minimal flask zappa tutorial to know more.

If there's something I'm missing and you really have to pass zappa_settings.json file, you can't pass it, but you can keep a backup in your repository as zappa_settings.json.backup and right after zappa init you can call cp zappa_settings.json.backup zappa_settings.json. This will save you from creating that file from scratch again and again.

Sign up to request clarification or add additional context in comments.

6 Comments

got it @amsh, I have one more small question, when i run zappa package test -o mypackage.zip i am seeing 2 different zip files like mypackage.zip and <PROJECT_NAME>-dev-1602262819.tar.gz . which one is correct?
mypackage.zip should be the right one. This claim is backed by the documentation: github.com/Miserlou/Zappa#package
@siva, if the answer was helpful, it's requested to accept and upvote it. Thanks
i will do that, at present to run lambda i am uploading these compressed files to s3 and my CI/CD setup will fatch these compressed files into lambda. finally my lambda will process the code.
do i need to upload both mypackage.zip and <PROJECT_NAME>-dev-1602262819.tar.gz to s3?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.