lambda-tutorial icon indicating copy to clipboard operation
lambda-tutorial copied to clipboard

Modifications to initial db connect code

Open prabhathn opened this issue 6 years ago • 0 comments

A few minor updates in the Setting Environment variables are needed to get this to run properly (mainly steps for less savvy learners).

  1. Add import pymysql to the import list. Add the corresponding pip commands as well to install on the environment
  2. It looks like the dotenv package is actually python-dotenv
  3. Most of the code to retrieve environment variables could be written as the following:
import os
import logging
import pymysql
from dotenv import load_dotenv
from flask import Flask, Response, json, request

app = Flask(__name__)

# update environment just in case
load_dotenv()

# set globals
RDS_HOST = os.getenv("DB_HOST")
RDS_PORT = int(os.getenv("DB_PORT"))
NAME = os.getenv("DB_USERNAME")
PASSWORD = os.getenv("DB_PASSWORD")
DB_NAME = os.getenv("DB_NAME")

# we need to instantiate the logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)

prabhathn avatar Jan 24 '20 05:01 prabhathn