def __init__(self, event, context): """ Initializes helper setup class :param event: :param context: """ CustomResource.__init__(self, event, context) # get "clean" set of arguments self.arguments = copy(self.resource_properties) self.arguments = { a: self.resource_properties[a] for a in self.resource_properties if a not in ["ServiceToken", "Timeout"] } self.configuration_bucket = os.getenv(configuration.ENV_CONFIG_BUCKET, None) self.scheduler_role_arn = self.arguments.get("SchedulerRole") # setup logging dt = datetime.utcnow() classname = self.__class__.__name__ logstream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day) self._logger = Logger(logstream=logstream, context=context, buffersize=10)
def handle_request(self): """ Handles the custom resource request to write scheduler global settings to config database :return: """ try: self._logger.info("Handler {} : Received request {}", self.__class__.__name__, json.dumps(self.event)) CustomResource.handle_request(self) finally: self._logger.flush()
def __init__(self, event, context): CustomResource.__init__(self, event, context) # Setup logging classname = self.__class__.__name__ dt = datetime.utcnow() log_stream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day) self._logger = Logger(logstream=log_stream, buffersize=1, context=context) self.arguments = copy(self.resource_properties) self.arguments = {a: self.resource_properties[a] for a in self.resource_properties if a not in ["ServiceToken", "Timeout"]} self._stack_version = self.arguments["stack_version"]
def __init__(self, event, context): """ Initializes instance :param event: CFN event :param context: Lambda context """ CustomResource.__init__(self, event, context) self.number_of_periods = 0 classname = self.__class__.__name__ dt = datetime.utcnow() logstream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day) self._logger = Logger(logstream=logstream, buffersize=20, context=context) self._admin = ConfigAdmin(logger=self._logger, context=context)
def handle_request(self): """ Handles the custom resource request from cloudformation :return: """ start = datetime.now() self._logger.info("Handler {}", self.__class__.__name__) self._logger.info("Cloudformation request is {}", safe_json(self._event, indent=2)) try: result = CustomResource.handle_request(self) return safe_dict({ "result": result, "datetime": datetime.now().isoformat(), "running-time": (datetime.now() - start).total_seconds() }) except Exception as ex: self._logger.error("{} {}", ex, traceback.format_exc()) raise ex finally: self._logger.flush()
def handle_request(self): start = datetime.now() self._logger.info("Handler {}", self.__class__.__name__) self._logger.info("Cloudformation request is {}", safe_json(self._event, indent=2)) try: result = CustomResource.handle_request(self) return safe_dict({ "datetime": datetime.now().isoformat(), "running-time": (datetime.now() - start).total_seconds(), "result": result }) finally: self._logger.flush()