I am having a use case where very large .gz files are generated by a snowflake and stored in S3.
Now I want to convert each file separately into zip files using Python, AWS Lamda, and boto3.
Getting exception with below code. can someone help me with it
def convert_gz_s3_files(prefix):
s3 = boto3.session.Session().client('s3')
gzFiles = getGZFiles(s3, prefix)
try:
for gzipFile in gzFiles:
obj = s3.get_object(Bucket=bucket, Key=gzipFile[0])
with gzip.GzipFile(fileobj=obj['Body']) as gz:
data = gz.read().decode()
archive = zipfile.ZipFile(data, mode="r")
# with zipfile.ZipFile(data, mode='w', allowZip64 = True) as zip:
# zipData = zip.read().decode()
# zipObject = s3.Object(bucket, prefix+'file_name.csv.zip')
# zipRes = zipObject.put(body=zipData)
# print('zip result => {}', zipRes)
print(gzipFile)
except Exception as e:
logger.error({'error': str(e), 'message': 'failed gzip decoding'})
raise e
print(gzFiles)