简体   繁体   中英

File open and read in AWS Glue with Python

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()

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'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM