Introduction: Rather than saying that Serverless architecture is a new concept, it is a brand new idea and a new programming paradigm.
However, there are very few native Serverless development frameworks. Taking Web framework as an example, the current mainstream Web frameworks "do not support Serverless mode deployment". Therefore, on the one hand, we must try to contact Serverless, but on the other hand, we cannot completely abandon traditional frameworks. Therefore, how to deploy traditional frameworks to the Serverless architecture simpler, faster and more scientifically is a question worth discussing.
request integration solution
request integration solution is actually to pass the real API gateway request directly to the FaaS platform without adding any conversion logic in the middle. Taking the HTTP function calculated by Alibaba Cloud function as an example, when you want to deploy traditional frameworks (such as Django, Flask, Express, Next.js, etc.) to the Alibaba Cloud function computing platform and experience the dividends such as pay-as-quantity, elastic scaling, etc. brought by the Serverless architecture, thanks to the HTTP function and HTTP triggers for Alibaba Cloud function computing, users can not only quickly and simply deploy the framework to the Alibaba Cloud function computing platform, but also get the same experience as traditional development.
For example, develop a Bottle project with the Bottle framework of Python;
# index.pyimport [email protected]('/hello/name')def index(name): return "Hello world"if __name__ == '__main__': bottle.run(host='localhost', port=8080, debug=True)
, you can debug directly locally. When you want to deploy the project to the Alibaba Cloud function computing platform, you only need to add a default_app object:
app = bottle.default_app()
The code of the entire project is as follows:
# index.pyimport [email protected]('/hello/name')def index(name):return "Hello world"app = bottle.default_app()if __name__ == '__main__': bottle.run(host='localhost', port=8080, debug=True)
If you create a function on the Alibaba Cloud Function Computing Platform, set the entry function to index.app. Except for the Bottle framework, the operation methods of other web frameworks are similar. Take Flask as an example:
# index.pyfrom flask import Flaskapp = Flask(__name__)@app.route('/')def hello_world(): return 'Hello, World!'if __name__ == '__main__': app.run( host="0.0.0.0",port=int("8001"))
When creating a function, set the entry function to index.app, which can ensure that the Flask project runs on the function computing platform.
Of course, in addition to using the existing linguistic Runtime (referring to the runtime of a specific language, such as the Python3 runtime and Node. js12 runtime), we can also consider using Custom Runtime and Custom Container to implement it. For example, after a web project is completed, we can write an Bootstrap file (write some startup commands in the Bootstrap file).
For example, to start an Express project, after the Express project is completed, you can directly create a Bootstrap file and configure the startup command to the file:
#!/usr/bin/env bashexport PORT=9000npm run star
Alibaba Cloud function calculation also provides a simpler Web framework migration solution. As shown in the figure, is an example of the migration function of the traditional web framework of Alibaba Cloud Function Computing Page.
Ali Cloud Function Computing Page Traditional Web Framework Migration Function
After selecting the corresponding environment, you only need to upload the code and make simple configurations to allow the traditional Web Framework to migrate to the Alibaba Cloud Function Computing Platform.
If deployed through developer tools, take Serverless Devs as an example, first create index.py:
# -*-coding: utf-8 -*-from bottle import route, run@route('/')def hello(): return "Hello World!"run(host='0.0.0.0', debug=False, port=9000)
Click the link to view the original text to get more benefits!
https://developer.aliyun.com/article/1050376?spm=a2c6h.26396819.creator-center.14.5ef23e18lIMITC?utm_content=g_1000361766
Copyright Statement: The content of this article is spontaneously contributed by the registered user of Alibaba Cloud, and the copyright belongs to the original author. The Alibaba Cloud developer community does not own its copyright and does not assume corresponding legal responsibilities. For specific rules, please refer to the "Ali Cloud Developer Community User Service Agreement" and the "Ali Cloud Developer Community Intellectual Property Protection Guidelines". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will immediately delete the content suspected of infringement.