FLASK + LAMBDA
1-. No hay mantenimiento de servidor
2-. Solo pagas por lo que utilizas
3-. Fiabilidad y disponibilidad constante
The request comes in through an API Gateway
The API request is mapped to a dictionary using Velocity Template Language (VTL)
A server is created
The server then converts the dictionary to a standard Python WSGI and feeds it into the application
The application returns it, and it passes it through the API Gateway
The server is destroyed
1-. Creamos nuestra carpeta con package json
1 $ mkdir api-serveless 2 $ cd api-serveless 3 $ npm init -f
2-. Instalamos dependencias
1 $ npm install --save-dev serverless-wsgi serverless-python-requirements
3-. Empezamos a escribir nuestra aplicación
1 $ touch app.py
1 # app.py
2
3 from flask import Flask
4 app = Flask(__name__)
5
6 @app.route("/me")
7 def me():
8 return {
9 'data': {
10 'name': 'Betsy',
11 } 12 }
1 $ touch serverless.yml
1 # serverless.ylm
2
3 service: api-serverless
4
5 plugins:
6 - serverless-python-requirements
7 - serverless-wsgi
8
9 custom:
10 wsgi:
11 app: app.app
12 packRequirements: false
13 pythonRequirements:
14 dockerizePip: non-linux
15
16 provider:
17 name: aws
18 runtime: python3.6
19 stage: dev
20 region: us-east-1
21 - serverless-wsgi
22
23 functions:
24 app:
25 handler: wsgi.handler
26 events:
27 - http: ANY/
28 - http: 'ANY{proxy+}'
4-. Para el deploy creamos nuestro archivo serverless
5-. Instalamos flask, creamos nuestro ambiente virtual y lo activamos
1 $ virtualenv venv --python=python3 2 $ source venv/bin/activate
1 (venv) $ pip install flask 2 (venv) $ pip freeze > requirements.txt
5-. Deploy!!
1 $ sls deploy
6-. Trabaja en local
1 $ sls wsgi serve
betsai.mendozagomez@gmail.com