Module aws_lambda_powertools.utilities.data_classes.cloud_watch_logs_event
Expand source code
import base64
import json
import zlib
from typing import Dict, List, Optional
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper
class CloudWatchLogsLogEvent(DictWrapper):
@property
def get_id(self) -> str:
"""The ID property is a unique identifier for every log event."""
# Note: this name conflicts with existing python builtins
return self["id"]
@property
def timestamp(self) -> int:
"""Get the `timestamp` property"""
return self["timestamp"]
@property
def message(self) -> str:
"""Get the `message` property"""
return self["message"]
@property
def extracted_fields(self) -> Optional[Dict[str, str]]:
"""Get the `extractedFields` property"""
return self.get("extractedFields")
class CloudWatchLogsDecodedData(DictWrapper):
@property
def owner(self) -> str:
"""The AWS Account ID of the originating log data."""
return self["owner"]
@property
def log_group(self) -> str:
"""The log group name of the originating log data."""
return self["logGroup"]
@property
def log_stream(self) -> str:
"""The log stream name of the originating log data."""
return self["logStream"]
@property
def subscription_filters(self) -> List[str]:
"""The list of subscription filter names that matched with the originating log data."""
return self["subscriptionFilters"]
@property
def message_type(self) -> str:
"""Data messages will use the "DATA_MESSAGE" type.
Sometimes CloudWatch Logs may emit Kinesis records with a "CONTROL_MESSAGE" type,
mainly for checking if the destination is reachable.
"""
return self["messageType"]
@property
def log_events(self) -> List[CloudWatchLogsLogEvent]:
"""The actual log data, represented as an array of log event records.
The ID property is a unique identifier for every log event.
"""
return [CloudWatchLogsLogEvent(i) for i in self["logEvents"]]
class CloudWatchLogsEvent(DictWrapper):
"""CloudWatch Logs log stream event
You can use a Lambda function to monitor and analyze logs from an Amazon CloudWatch Logs log stream.
Documentation:
--------------
- https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchlogs.html
"""
_decompressed_logs_data = None
_json_logs_data = None
@property
def raw_logs_data(self) -> str:
"""The value of the `data` field is a Base64 encoded ZIP archive."""
return self["awslogs"]["data"]
@property
def decompress_logs_data(self) -> bytes:
"""Decode and decompress log data"""
if self._decompressed_logs_data is None:
payload = base64.b64decode(self.raw_logs_data)
self._decompressed_logs_data = zlib.decompress(payload, zlib.MAX_WBITS | 32)
return self._decompressed_logs_data
def parse_logs_data(self) -> CloudWatchLogsDecodedData:
"""Decode, decompress and parse json data as CloudWatchLogsDecodedData"""
if self._json_logs_data is None:
self._json_logs_data = json.loads(self.decompress_logs_data.decode("UTF-8"))
return CloudWatchLogsDecodedData(self._json_logs_data)
Classes
class CloudWatchLogsDecodedData (data: Dict[str, Any])
-
Provides a single read only access to a wrapper dict
Expand source code
class CloudWatchLogsDecodedData(DictWrapper): @property def owner(self) -> str: """The AWS Account ID of the originating log data.""" return self["owner"] @property def log_group(self) -> str: """The log group name of the originating log data.""" return self["logGroup"] @property def log_stream(self) -> str: """The log stream name of the originating log data.""" return self["logStream"] @property def subscription_filters(self) -> List[str]: """The list of subscription filter names that matched with the originating log data.""" return self["subscriptionFilters"] @property def message_type(self) -> str: """Data messages will use the "DATA_MESSAGE" type. Sometimes CloudWatch Logs may emit Kinesis records with a "CONTROL_MESSAGE" type, mainly for checking if the destination is reachable. """ return self["messageType"] @property def log_events(self) -> List[CloudWatchLogsLogEvent]: """The actual log data, represented as an array of log event records. The ID property is a unique identifier for every log event. """ return [CloudWatchLogsLogEvent(i) for i in self["logEvents"]]
Ancestors
Instance variables
var log_events : List[CloudWatchLogsLogEvent]
-
The actual log data, represented as an array of log event records.
The ID property is a unique identifier for every log event.
Expand source code
@property def log_events(self) -> List[CloudWatchLogsLogEvent]: """The actual log data, represented as an array of log event records. The ID property is a unique identifier for every log event. """ return [CloudWatchLogsLogEvent(i) for i in self["logEvents"]]
var log_group : str
-
The log group name of the originating log data.
Expand source code
@property def log_group(self) -> str: """The log group name of the originating log data.""" return self["logGroup"]
var log_stream : str
-
The log stream name of the originating log data.
Expand source code
@property def log_stream(self) -> str: """The log stream name of the originating log data.""" return self["logStream"]
var message_type : str
-
Data messages will use the "DATA_MESSAGE" type.
Sometimes CloudWatch Logs may emit Kinesis records with a "CONTROL_MESSAGE" type, mainly for checking if the destination is reachable.
Expand source code
@property def message_type(self) -> str: """Data messages will use the "DATA_MESSAGE" type. Sometimes CloudWatch Logs may emit Kinesis records with a "CONTROL_MESSAGE" type, mainly for checking if the destination is reachable. """ return self["messageType"]
var owner : str
-
The AWS Account ID of the originating log data.
Expand source code
@property def owner(self) -> str: """The AWS Account ID of the originating log data.""" return self["owner"]
var subscription_filters : List[str]
-
The list of subscription filter names that matched with the originating log data.
Expand source code
@property def subscription_filters(self) -> List[str]: """The list of subscription filter names that matched with the originating log data.""" return self["subscriptionFilters"]
Inherited members
class CloudWatchLogsEvent (data: Dict[str, Any])
-
CloudWatch Logs log stream event
You can use a Lambda function to monitor and analyze logs from an Amazon CloudWatch Logs log stream.
Documentation:
Expand source code
class CloudWatchLogsEvent(DictWrapper): """CloudWatch Logs log stream event You can use a Lambda function to monitor and analyze logs from an Amazon CloudWatch Logs log stream. Documentation: -------------- - https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchlogs.html """ _decompressed_logs_data = None _json_logs_data = None @property def raw_logs_data(self) -> str: """The value of the `data` field is a Base64 encoded ZIP archive.""" return self["awslogs"]["data"] @property def decompress_logs_data(self) -> bytes: """Decode and decompress log data""" if self._decompressed_logs_data is None: payload = base64.b64decode(self.raw_logs_data) self._decompressed_logs_data = zlib.decompress(payload, zlib.MAX_WBITS | 32) return self._decompressed_logs_data def parse_logs_data(self) -> CloudWatchLogsDecodedData: """Decode, decompress and parse json data as CloudWatchLogsDecodedData""" if self._json_logs_data is None: self._json_logs_data = json.loads(self.decompress_logs_data.decode("UTF-8")) return CloudWatchLogsDecodedData(self._json_logs_data)
Ancestors
Instance variables
var decompress_logs_data : bytes
-
Decode and decompress log data
Expand source code
@property def decompress_logs_data(self) -> bytes: """Decode and decompress log data""" if self._decompressed_logs_data is None: payload = base64.b64decode(self.raw_logs_data) self._decompressed_logs_data = zlib.decompress(payload, zlib.MAX_WBITS | 32) return self._decompressed_logs_data
var raw_logs_data : str
-
The value of the
data
field is a Base64 encoded ZIP archive.Expand source code
@property def raw_logs_data(self) -> str: """The value of the `data` field is a Base64 encoded ZIP archive.""" return self["awslogs"]["data"]
Methods
def parse_logs_data(self) ‑> CloudWatchLogsDecodedData
-
Decode, decompress and parse json data as CloudWatchLogsDecodedData
Expand source code
def parse_logs_data(self) -> CloudWatchLogsDecodedData: """Decode, decompress and parse json data as CloudWatchLogsDecodedData""" if self._json_logs_data is None: self._json_logs_data = json.loads(self.decompress_logs_data.decode("UTF-8")) return CloudWatchLogsDecodedData(self._json_logs_data)
Inherited members
class CloudWatchLogsLogEvent (data: Dict[str, Any])
-
Provides a single read only access to a wrapper dict
Expand source code
class CloudWatchLogsLogEvent(DictWrapper): @property def get_id(self) -> str: """The ID property is a unique identifier for every log event.""" # Note: this name conflicts with existing python builtins return self["id"] @property def timestamp(self) -> int: """Get the `timestamp` property""" return self["timestamp"] @property def message(self) -> str: """Get the `message` property""" return self["message"] @property def extracted_fields(self) -> Optional[Dict[str, str]]: """Get the `extractedFields` property""" return self.get("extractedFields")
Ancestors
Instance variables
var extracted_fields : Union[Dict[str, str], NoneType]
-
Get the
extractedFields
propertyExpand source code
@property def extracted_fields(self) -> Optional[Dict[str, str]]: """Get the `extractedFields` property""" return self.get("extractedFields")
var get_id : str
-
The ID property is a unique identifier for every log event.
Expand source code
@property def get_id(self) -> str: """The ID property is a unique identifier for every log event.""" # Note: this name conflicts with existing python builtins return self["id"]
var message : str
-
Get the
message
propertyExpand source code
@property def message(self) -> str: """Get the `message` property""" return self["message"]
var timestamp : int
-
Get the
timestamp
propertyExpand source code
@property def timestamp(self) -> int: """Get the `timestamp` property""" return self["timestamp"]
Inherited members