All About Zappa - What Is It & Why Do We Need It
Zappa is a very lightweight and powerful tool which allows you to deploy and update python applications to AWS. Using Zappa you can host your WSGI app on AWS Lambda, API Gateway quickly.
Generally, we prefer to use a VM to host our python application and the VM is costly compared to serverless technology because it will be up and running all the time and the cloud provider is billing us as per run time. Pricing based on the amount of computing power, storage, and time.
- Infinite scaling
- Zero downtime
- Zero maintenance
Nowadays serverless is in a buzz. Actually without any server we can’t host our application there is a resource which is available on demand. "Serverless computing is a cloud computing execution model in which the cloud provider allocates machine resources on demand, taking care of the servers on behalf of their customers."
AWS EC2 is a service that provides traditional cloud infrastructure (IaaS) and allows us to run EC2 instances as VMs. AWS Lambda provides us a serverless architecture and allows you to run arbitrary event-driven code in the cloud after an event trigger is activated.
There are many alternatives available for Zappa :
Step 1 : Create a project folder called “myflask".
> mkdir myflask
Step 2 : Create a “requirements.txt” file inside of the myflask folder.
Flask==2.0.1
zappa==0.48.2
Step 3 : Create Virtual Environment
>virtualenv env
Step 4 : Activate Your env
(Windows) D:\zappaTest>env\Scripts\activate
(Mac) $ source env/bin/activate
Step 5 : Install Dependencies in Environment
(env)> pip3 install -r requirements.txt
Step 6 : Create an index.py file for Flask.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route('/hello')
def hello_world1():
return 'Hello, World1!'
if __name__ == '__main__':
app.run(host="0.0.0.0", port=3000, debug=True)
Step 7 : Test Flask
(env)> python3 index.py

Step 8 : Create a Zappa configuration file.
(env)> zappa init
(read all instructions)
{
"dev": {
"aws_region": "ap-south-1",
"django_settings": "myproject.settings",
"profile_name": "default",
"project_name": "project",
"runtime": "python3.6",
"s3_bucket": "zappa-ga67u69nx"
}
}
Step 9 : Setup your aws configure
There is two ways to configure your aws credentials using AWS command or updating credentials file if you want to go with command then you must have awscli installed into your local machine if not install using
> pip3 install awscli
> aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json
OR
> vi ~/.aws/credentials
[default]
aws_access_key_id = 'abc'
aws_secret_access_key = '123’
Step 10 : Deploy Flask
(env)>zappa deploy
(env)>zappa deploy

Step 11: After Deploying Check Server Log
(env)D:\zappaTest>zappa tail

Step 12: Update Codebase
(env)D:\zappaTest>zappa update dev
Step 13: If you want to remove this project from aws
(env)D:\zappaTest>zappa undeploy
(env)D:\zappaTest>zappa undeploy

Full Stack Developer - NeenOpal Analytics @Anshuman Sharma
Other Blogs

Google App Script
June 08, 2021

Docker
June 08, 2021

Azure Functions vs Azure Data Factory
August 25, 2020
Leave a reply