Deploying a service to store sensor data in a MySQL database
For this scenario, we need to deploy a service to store data in the previously deployed MySQL. We are going to call this metrics
. The metrics
service contains the following code:
from flask import Flask, request import mysql.connector import os app = Flask(__name__) @app.route('/') def hello_world(): return 'It works' def insert(data): conn = mysql.connector.connect( host=os.environ['HOST'], user=os.environ['MYSQL_USER'], password=os.environ['MYSQL_PASSWORD'], database=os.environ['MYSQL_DATABASE'] ) cursor = conn.cursor() sql = "INSERT INTO metric "+\ ...