Home > OS >  File open and read in AWS Glue with Python
File open and read in AWS Glue with Python

Time:12-17

I have a simple python code below. This is written in desktop, now I want to recreate this to aws glue or lambda, I have to read the testfile.csv from a s3 directory and put to txt just like below. how this open and read can be recreated in aws glue/lambda environment. Any input is appreciated.

filepath = testfile.csv
txt = open(filepath).read()

CodePudding user response:

I have found the solution to this. The first line store the file as byte object and second line convert it to string and store to txt.

object = s3client.get_object(Bucket='mybucket',Key='testfile.csv')
txt = (object['Body'].read().decode('utf-8'))
  • Related