我正在使用aws lambda
来加载存储在s3中的csv文件,如何逐行读取响应的内容,就像从csv.reader()
读取的那样。
reader = csv.reader(f)
for line in reader:
#do something
line[1] = line[1].lower()
Lambda函数:
import urllib
import boto3
print('Loading function')
s3 = boto3.client('s3')
def lambda_handler(event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'].encode('utf8'))
response = s3.get_object(Bucket=bucket, Key=key)
content = response['Body'].read()
#read content line by line as a list
答案 0 :(得分:1)
content.splitlines()
会为你效力吗?
for line in content.splitlines():
# do something with line