예제 #1
0
 def run_log_loop(self) -> None:
     while not self._shutdown_event.is_set():
         log_item = self.log_queue.get()
         if log_item is QUEUE_SHUTDOWN:
             return
         store_cloudwatch_logs(log_item.log_group, log_item.log_stream,
                               log_item.logs)
예제 #2
0
 def _store_logs(self, func_details, log_output, invocation_time):
     log_group_name = '/aws/lambda/%s' % func_details.name()
     invocation_time_secs = int(invocation_time / 1000)
     time_str = time.strftime('%Y/%m/%d', time.gmtime(invocation_time_secs))
     log_stream_name = '%s/[$LATEST]%s' % (time_str, short_uid())
     return store_cloudwatch_logs(log_group_name, log_stream_name,
                                  log_output, invocation_time)
예제 #3
0
def store_delivery_log(
    subscriber: dict, success: bool, message: str, message_id: str, delivery: dict = None
):

    log_group_name = subscriber.get("TopicArn", "").replace("arn:aws:", "").replace(":", "/")
    log_stream_name = long_uid()
    invocation_time = int(time.time() * 1000)

    delivery = not_none_or(delivery, {})
    delivery["deliveryId"] = (long_uid(),)
    delivery["destination"] = (subscriber.get("Endpoint", ""),)
    delivery["dwellTimeMs"] = 200
    if not success:
        delivery["attemps"] = 1

    delivery_log = {
        "notification": {
            "messageMD5Sum": md5(message),
            "messageId": message_id,
            "topicArn": subscriber.get("TopicArn"),
            "timestamp": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f%z"),
        },
        "delivery": delivery,
        "status": "SUCCESS" if success else "FAILURE",
    }

    log_output = json.dumps(json_safe(delivery_log))

    return store_cloudwatch_logs(log_group_name, log_stream_name, log_output, invocation_time)
예제 #4
0
def _store_logs(func_details, log_output, invocation_time=None, container_id=None):
    log_group_name = '/aws/lambda/%s' % func_details.name()
    container_id = container_id or short_uid()
    invocation_time = invocation_time or int(time.time() * 1000)
    invocation_time_secs = int(invocation_time / 1000)
    time_str = time.strftime('%Y/%m/%d', time.gmtime(invocation_time_secs))
    log_stream_name = '%s/[LATEST]%s' % (time_str, container_id)
    return store_cloudwatch_logs(log_group_name, log_stream_name, log_output, invocation_time)
예제 #5
0
def store_lambda_logs(lambda_function: LambdaFunction,
                      log_output: str,
                      invocation_time=None,
                      container_id=None):
    log_group_name = "/aws/lambda/%s" % lambda_function.name()
    container_id = container_id or short_uid()
    invocation_time = invocation_time or int(time.time() * 1000)
    invocation_time_secs = int(invocation_time / 1000)
    time_str = time.strftime("%Y/%m/%d", time.gmtime(invocation_time_secs))
    log_stream_name = "%s/[LATEST]%s" % (time_str, container_id)
    return store_cloudwatch_logs(log_group_name, log_stream_name, log_output,
                                 invocation_time)
예제 #6
0
def store_lambda_logs(lambda_function: LambdaFunction,
                      log_output: str,
                      invocation_time=None,
                      container_id=None):
    # leave here to avoid import issues from CLI
    from localstack.utils.cloudwatch.cloudwatch_util import store_cloudwatch_logs

    log_group_name = "/aws/lambda/%s" % lambda_function.name()
    container_id = container_id or short_uid()
    invocation_time = invocation_time or int(time.time() * 1000)
    invocation_time_secs = int(invocation_time / 1000)
    time_str = time.strftime("%Y/%m/%d", time.gmtime(invocation_time_secs))
    log_stream_name = "%s/[LATEST]%s" % (time_str, container_id)
    return store_cloudwatch_logs(log_group_name, log_stream_name, log_output,
                                 invocation_time)