Tencent Cloud Flask Serverless Component
npm install @serverless/tencent-flask
简体中文 | English
Tencent Flask Serverless Component, support Restful API deploy, not supportting Flask command.
1. Prepare
1. Install
1. Create
1. Configure
1. Deploy
1. Remove
Before using this component, you need create a flask project, then add Flask and werkzeug in requirements.txt. Like below:
``txt`
Flask==1.0.2
werkzeug==0.16.0
Then create your API service entry file app.py, below is a example:
`python
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def index():
return "Hello Flash"
@app.route("/users")
def users():
users = [{'name': 'test1'}, {'name': 'test2'}]
return jsonify(data=users)
@app.route("/users/
def user(id):
return jsonify(data={'name': 'test1'})
`
Install the Serverless Framework globally:
`shell`
$ npm install -g serverless
Just create the following simple boilerplate:
`shell`
$ touch serverless.yml
$ touch .env # your Tencent api keys
Add the access keys of a Tencent CAM Role with AdministratorAccess in the .env file, using this format:
``.env
TENCENT_SECRET_ID=XXX
TENCENT_SECRET_KEY=XXX
- If you don't have a Tencent Cloud account, you could sign up first.
`ymlserverless.yml
MyComponent:
component: '@serverless/tencent-flask'
inputs:
region: ap-guangzhou
functionName: flask-function
code: ./
functionConf:
timeout: 10
memorySize: 128
environment:
variables:
TEST: vale
vpcConfig:
subnetId: ''
vpcId: ''
apigatewayConf:
protocol: https
environment: release
`
`shell`
$ sls --debug
`shell``
$ sls remove --debug
Checkout the Serverless Components repo for more information.