Home > Mobile >  read .txt file from s3 bucket not returning all file content
read .txt file from s3 bucket not returning all file content

Time:09-22

I am trying to read a .txt file content from s3 bucket and return all its lines. I managed to do it this way:

s3 = boto3.resource('s3')
res = s3_client.Object(bucket_name, key_name)
    

data = res.get()['Body'].read().decode('utf-8').splitlines()

    
for i in data:
        
   print(i)

It printing content but it only prints the 30 last lines and I wanted it to return all of its content.

CodePudding user response:

CloudWatch Logs for this Lambda function should be the definitive view of the printed logs.

Your code looks to be correct - the read function on StreamingBody returns all data (if you don't specify an amount parameter), so I don't think there's a problem with your code. It is receiving the entire file contents.

It looks like the truncated view you are seeing in the Lambda console may simply be a limitation of the console, in order to avoid showing an overwhelming number of lines of output.

  • Related