Answers for "how to read the csv file using pandas in aws lambda"

0

how to read the csv file using pandas in aws lambda

import json
import os
import boto3
import csv
import sys
import pandas as pd
from io import BytesIO

s3_client = boto3.client('s3')

bucket_name ='bucket_name'
s3_file_name ='s3_file_name.csv'

def lambda_handler(event, context):
    print(event)
    try:
        #   bucket_name = event["Records"][0]["s3"]["bucket"]["name"]
        #   s3_file_name = event["Records"][0]["s3"]["object"]["key"]
        resp = s3_client.get_object(Bucket=bucket_name, Key=s3_file_name)
        df= pd.read_csv(resp['Body'], sep=',')

        print(df.head(2))
    except Exception as err:
        print(err)
Posted by: Guest on June-01-2021

Code answers related to "how to read the csv file using pandas in aws lambda"

Python Answers by Framework

Browse Popular Code Answers by Language