import os from config_helper import AppConfigHelper from flask import Flask import boto3 from botocore.exceptions import ClientError app = Flask(__name__) # Attempt to refresh config every 1 hour CONFIG_REFRESH_TIME = 3600 appconfig = AppConfigHelper( os.environ['ConfigApp'], os.environ['ConfigEnv'], os.environ['ConfigProfile'], CONFIG_REFRESH_TIME, os.environ['ConfigClient'] ) @app.route('/') def health(): """ Health check endpoint for the load balancer to poll """ return "All good !" @app.route('/hello') def hello_world(): """ Display hello message using the information from the Dynamo table """ ddb_client = boto3.client( 'dynamodb', region_name=os.environ['AWS_DEFAULT_REGION']) TABLE_NAME = get_table_name() try: response = ddb_client.get_item( TableName=TABLE_NAME, Key={'Application': {'S': 'TwelveFactorApp'}}) return f"
"\ f"Hello from {response['Item']['Name']['S']}!