Description
Use case
We are currently passing Cloudwatch logs to a Kinesis stream to be subsequently processed by a Lambda. We'd like to use the cloud_watch_logs_event data class but it only works when the source is Cloudwatch directly, not Kinesis. It seems when Cloudwatch targets Lambda, it wraps the payload in the following superstructure:
'awslogs': {'data': {<PAYLOAD>}}
You can see that the existing CloudWatchLogsEvent
class' raw_logs_data
property expects this structure to unpack the data.
This superstructure doesn't show up when the logs are passed through kinesis
Solution/User Experience
I think a new method/property within the CloudWatchLogsEvent
class, perhaps named parse_logs_kinesis()
or something, which can be used to unpack this type of payload, could work.
However that may be less than ideal since accidentally using the existing raw_logs_data
property would then cause issues, so it's possible that an entirely new class (like CloudWatchLogsKinesisEvent
, ex) would be preferable.
A third option would be to rewrite the existing raw_logs_data
property, such that it checks for the presence of the Cloudwatch->Lambda superstructure:
return self['awslogs']['data'] if self.get('awslogs') else self[0]
(safe retrieval from nested dicts can get a bit klunky)
Note: Originally posted in discussions forum here.
Alternative solutions
No response
Acknowledgment
- This feature request meets Lambda Powertools Tenets
- Should this be considered in other Lambda Powertools languages? i.e. Java, TypeScript