creating raw AWS log event

Larry Martell larry.martell at gmail.com
Wed Jun 23 22:26:07 EDT 2021


On Wed, Jun 23, 2021 at 7:05 PM Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>
> On Wed, 23 Jun 2021 10:42:42 -0700, Larry Martell <larry.martell at gmail.com>
> declaimed the following:
>
> >def _decode(data):
> >    compressed_payload = b64decode(data)
> >    json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS)
> >    return json.loads(json_payload)
> >
>
> >message  = b'test message'
> >compressed= zlib.compress(message)
> >event['awslogs']['data'] = str(compressed)
>
>         Where do you perform a B64 ENCODE operation?
>
>         str() doesn't do that, it just converts the argument to a string which
> may mean using escapes for non-printable bytes. B64 converts everything to
> printable characters.

Copy/paste fail. This is actually the code I tried:

message = b'test message'
compressed= zlib.compress(message)
encoded = b64encode(compressed)
event['awslogs']['data'] = str(encoded)
message = _decode(json.dumps(event['awslogs']['data']))


More information about the Python-list mailing list