creating raw AWS log event

Grant Edwards grant.b.edwards at gmail.com
Thu Jun 24 10:42:55 EDT 2021


On 2021-06-24, Larry Martell <larry.martell at gmail.com> wrote:
> 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)

Try printout out the result of each step:

    >>> encoded
    b'eJwrSS0uUchNLS5OTE8FAB8fBMY='
    >>> str(encoded)
    "b'eJwrSS0uUchNLS5OTE8FAB8fBMY='"

Ah, that's not what you want, is it?

    >>> encoded.decode('ascii')
    'eJwrSS0uUchNLS5OTE8FAB8fBMY='

That's better.

-- 
Grant Edwards               grant.b.edwards        Yow! I think my career
                                  at               is ruined!
                              gmail.com            



More information about the Python-list mailing list