AUTOMATED CSV-DATA INGESTION FROM S3 TO DYNAMO DB USING AWS LAMBDA

Опубликовано: 10 Июль 2026
на канале: AWS SERVICE
63
2

THIS VEDIO FOR EDUCATIONAL PURPOSE AND HERE AFTER MORE VEDIOS ABOUT AWS WILL BE UPLOAD HERE.THANK YOU.
LIKE, SHARE AND SUBSCRIBE.

FUNCTION CODE:
import boto3
import csv
import io

Initialize AWS services
s3_client = boto3.client('s3')
dynamodb = boto3.resource('dynamodb')

Specify your table name
TABLE_NAME = 'CSVData'

def lambda_handler(event, context):
S3 bucket and object details from event
bucket_name = event['Records'][0]['s3']['bucket']['name']
object_key = event['Records'][0]['s3']['object']['key']

Fetch the CSV file from S3
response = s3_client.get_object(Bucket=bucket_name, Key=object_key)
csv_content = response['Body'].read().decode('utf-8')

Read the CSV file
csv_reader = csv.DictReader(io.StringIO(csv_content))

Connect to DynamoDB table
table = dynamodb.Table(TABLE_NAME)

Insert CSV rows into DynamoDB
for row in csv_reader:
table.put_item(Item=row)

return {"status": "Success", "message": "CSV data uploaded to DynamoDB"}

#s3 read only access
#dynamodb full access


EVENT CODE:
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "2025-02-28T12:34:56.789Z",
"eventName": "ObjectCreated:Put",
"s3": {
"bucket": {
"name": "my1-csv1-storage1"
},
"object": {
"key": "datas.csv"
}
}
}
]
}