Below is the code I am using to read gz file
import json
import boto3
from io import BytesIO
import gzip
def lambda_handler(event, context):
try:
s3 = boto3.resource('s3')
key='test.gz'
obj = s3.Object('athenaamit',key)
n = obj.get()['Body'].read()
#print(n)
gzip = BytesIO(n)
gzipfile = gzip.GzipFile(fileobj=gzip)
content = gzipfile.read()
print(content)
return 'dddd'
except Exception as e: print(e) raise e But I am gettting below error
"errorMessage": "'_io.BytesIO' object has no attribute 'GzipFile'",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 20, in lambda_handler\n raise e\n",
" File \"/var/task/lambda_function.py\", line 14, in lambda_handler\n gzipfile = gzip.GzipFile(fileobj=gzip)\n"
python version -3.7
I also tried to implement below suggestion https://stackoverflow.com/questions/32794837/pass-io-bytesio-object-to-gzip- gzipfile-and-write-to-gzipfile
but its also not working for me, kindly suggest how I can read content of file