def handler(event, context): # initialize logger module logger = Logger(event, context) # Load config handler config = Config(context) ## ==== Sample code to fetch environment specific configurations ==== # myconfig = config.get_config('default') === "default" is the section over here # logger.info ('One of the environment configuration: config_key => ' + myconfig['config_key']) ## ==== Log message samples ==== # logger.error('Runtime errors or unexpected conditions.') # logger.warn('Runtime situations that are undesirable, but not wrong') # logger.info('Interesting runtime events eg. connection established)') # logger.verbose('Generally speaking, most log lines should be verbose.') # logger.debug('Detailed information on the flow through the system.') myconfig = config.get_config('default') logger.info('Sample response for function1.') return { "message": "Your function executed successfully!", "event": event, "myconfig": myconfig['config_key'] }
def handler(event, context): try: # initialize logger module logger = Logger(event, context) # Load config handler. config = Config(event) ## ==== Sample code to fetch environment specific configurations ==== # myconfig = config.get_config('default') # logger.info ('One of the environment configuration: config_key => ' + myconfig['config_key']) ## ==== Log message samples ==== # logger.error('Runtime errors or unexpected conditions.') # logger.warn('Runtime situations that are undesirable, but not wrong') # logger.info('Interesting runtime events eg. connection established)') # logger.verbose('Generally speaking, most log lines should be verbose.') # logger.debug('Detailed information on the flow through the system.') # This is the happy path data = { 'key': 'value' } response = "" if 'method' in event: if event['method'] == "POST": # Handle Post response here logger.info('Sample log inside POST') response = CustomResponse(data, event['body']).get_json() else: # Handle Get/other response here. logger.info('Sample log inside GET') response = CustomResponse(data, event['query']).get_json() return response except Exception as e: # Exception Handling exception_type = e.__class__.__name__ # Create a JSON string here api_exception_json = CustomErrors.throwInternalServerError( str(e)) raise LambdaException(api_exception_json)
def handler(event, context): try: # initialze logger module logger = Logger(event, context) # Load config handler. config = Config(event) logger.error('Runtime errors or unexpected conditions.') logger.warn('Runtime situations that are undesirable, but not wrong') logger.info('Interesting runtime events eg. connection established)') logger.verbose('Generally speaking, most log lines should be verbose.') logger.debug('Detailed information on the flow through the system.') # This is the happy path data = { 'key': 'value' } response = "" if 'method' in event: if event['method'] == "POST": # Handle Post response here response = CustomResponse(data, event['body']).get_json() else: # Handle Get/other response here. response = CustomResponse(data, event['query']).get_json() return response except Exception as e: # Exception Handling exception_type = e.__class__.__name__ exception_message = e.message # Create a JSON string here api_exception_json = CustomErrors.throwInternalServerError( exception_message) raise LambdaException(api_exception_json)