2017-01-28 6 views
0

私はから読み取るように、1行ずつレスポンスの内容を読み込むにはどうすればいいですか?aws lambdaを使用してs3に格納されたcsvファイルをロードします。アマゾンラムダのレスポンス['Body']からデータを解析する方法

reader = csv.reader(f) 
for line in reader: 
    #do something 
    line[1] = line[1].lower() 

ラムダ関数:あなたのための

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 

答えて

1

content.splitlines()仕事?

for line in content.splitlines(): 
    # do something with line 
関連する問題