Serverless Flask WebApp with S3(for static content like images,css,js etc).
-
Install Python3.6
-
Git clone the repo
git clone https://github.com/vabhishek-me/serverless-flask-webapp-with-s3.git;
cd serverless-flask-webapp-with-s3;
-
Install
virtualenv
on your system to create a virtual environment.pip3 install virtualenv;
-
Create a virtualenv named
flaskenv
and activate it.virtualenv -p python3.6 flaskenv; source flaskenv/bin/activate;
-
Install all the dependencies.
pip install -r requirements.txt
-
To run the project locally:
python app.local.py # Open localhost:5000
.
├── static # Contains static files like images,css,js,videos etc. - will be pushed to s3 eventually
├── template # Contains all the templates - use `{{ url_for('static', filename='path/to/file') }}` for s3 links to work
├── app.py # Contains all the routing stuffs
├── app.local.py # To run project locally before deployment
├── upload-to-s3.py # Python script to upload content from static folder to s3 bucket - run it before deployment
├── requirements.txt # Python packages list - to recreate when new packages are installed, do "pip freeze > requirements.txt"
-
Add all your api-endpoints, static files and templates.
-
Run
upload-to-s3.py
script to upload all your static files to s3.
python3 upload-to-s3.py
-
Install ZAPPA. If you ran
pip install -r requirements.txt
before, you should have zappa installed. Otherwise, install usingpip install zappa
-
Run
zappa init
and provide the values as required for the configuration. -
Once configured, you'll see a
zappa_settings.json
file. -
Now, run
zappa deploy
to deploy your website. After successful deployment, You'll get an endpoint which you can use to visit your website.
Yayyy! Your site is live.