Created
August 3, 2021 10:36
-
-
Save pashri/55dfca4803640582a3d7acb5eb5684f3 to your computer and use it in GitHub Desktop.
Decode that base64 encoded gzipped json from AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gzip | |
import base64 | |
import io | |
import json | |
import pprint | |
def decode_mystery_message_from_aws(data: str) -> list: | |
"""Decodes a mystery message from AWS""" | |
decoded_data = base64.b64decode(data) | |
bytes_obj_data = io.BytesIO(decoded_data) | |
with gzip.open(bytes_obj_data, 'rb') as unzipped_data: | |
message = [ | |
json.loads(line.decode()) | |
for line in unzipped_data | |
] | |
return message | |
pprint.pprint(next(iter(decode_mystery_message_from_aws(data)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment