Wrappers
Upify uses wrapper files to adapt your application for cloud deployment:
upify_handler.[ext]
This file is automatically generated for all projects to handle cloud platform integration. You shouldn’t have to modify this file.
import os
from main import app
handler = None
if os.getenv("UPIFY_DEPLOY_PLATFORM") == "aws":
from apig_wsgi import make_lambda_handler
handler = make_lambda_handler(app)
if os.getenv("UPIFY_DEPLOY_PLATFORM") == "gcp":
import functions_framework
@functions_framework.http
def flask_function(request):
with app.request_context(request.environ):
return app.full_dispatch_request()
handler = flask_function
upify_main.[ext]
This file is only created for projects without a web framework. You’ll need to modify it to adapt your non-web framework code to be able to handle HTTP requests/responses.
from flask import Flask, request, jsonify
""" ADD YOUR IMPORTS HERE """
app = Flask(__name__, instance_path='/tmp')
@app.route('/')
def handler():
""" ADD YOUR CODE HERE """
Example Implementation
from flask import Flask, request, jsonify
from main import get_weather_data
app = Flask(__name__, instance_path='/tmp')
@app.route('/')
def handler():
city = request.args.get("city")
if city is None:
return jsonify({"error": "Specify a city"}), 400
try:
response_data = get_weather_data(city)
return jsonify(response_data), 200
except Exception as e:
return jsonify({"error": str(e)}), 500