AWS | Project | Final Part | Read S3 CSV file and insert into RDS mysql using Python Lambda Function

preview_player
Показать описание
import json
import csv
import boto3

def lambda_handler(event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
csv_file = event['Records'][0]['s3']['object']['key']
lines = response['Body'].read().decode('utf-8').split()
results = []
for row in csv.DictReader(lines):
print(results)

database='employeedb',
port='3306',
user='admin',
passwd='admin123')

mysql_insert = "insert into employee(empid,ename,salary) values(%s,%s,%s)"


return {
'statusCode': 200,
}
Рекомендации по теме
Комментарии
Автор

Excellent way of teaching very simple and effective, Thank you

shreenidhis
Автор

Thank you very much. You are awesome at explaining.

tejavitravels
Автор

Hello thank you.
In my case mssql is in EC2 instance.
Can you please tell me or do you have video of python layer creation which you used for this particular activity

aishwaryawalkar
Автор

Thank you very much for the video.How can I upload several text data files all containing comma seperated data with the same column names from S3 bucket to RDS postgres using python.Please can you provide the code?

debanjanamandal
Автор

Can you please share code or a video of how we can upload the same csv file into RDS Postgres?

anishmadhav
Автор

Explanation is wonderful. Could you please make a video or give code for uploading file to RDS Postgres?

kalyankumarkotturu
Автор

Amazing! Thank you! Do you have any idea how to load JSON files with nested values into RDS MySQL?

kennyosubor
Автор

How can upload same csv file to RDS ORACLE

qazisaifhussain
Автор

I tried the same thing but I used pymysql instead of mysql-connector. I could successfully upload hardcoded rows but when I tried to connect S3 bucket and RDS I keep getting this error


[ERROR] TypeError: not all arguments converted during string formatting
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 30, in lambda_handler
cursor.execute(mysql_test_insert_query, results)
File "/opt/python/lib/python3.8/site-packages/pymysql/cursors.py", line 146, in execute
query = self.mogrify(query, args)
File "/opt/python/lib/python3.8/site-packages/pymysql/cursors.py", line 125, in mogrify
query = query % self._escape_args(args, conn)
[ERROR] TypeError: not all arguments converted during string formatting Traceback (most recent call last): File "/var/task/lambda_function.py", line 30, in lambda_handler cursor.execute(mysql_test_insert_query, results) File "/opt/python/lib/python3.8/site-packages/pymysql/cursors.py", line 146, in execute query = self.mogrify(query, args) File "/opt/python/lib/python3.8/site-packages/pymysql/cursors.py", line 125, in mogrify query = query % self._escape_args(args, conn)



Please help

gayatrivlp
Автор

I keep getting this error. Is this saying it cannot read from my bucket? I followed all your steps in creating the bucket & the various functions.


Copy
[ERROR] KeyError: 'Records'
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 8, in lambda_handler
bucket =
[ERROR] KeyError: 'Records' Traceback (most recent call last): File "/var/task/lambda_function.py", line 8, in lambda_handler bucket =
I

leiaduva