Import CSV to AWS DynamoDB in Python

The following code shows how to import CSV data into AWS DynamoDB using Boto3 library in Python:

import boto3
import uuid
from csv import reader

MY_ACCESS_KEY_ID = 'Enter aws access key here'
MY_SECRET_ACCESS_KEY = 'Enter aws secret access key here'
aws_region = 'Enter aws region here'

def generate_id():
    return uuid.uuid1()
def batch_insert(items, dynamodb_table):
    with dynamodb_table.batch_writer() as batch:
        for r in items:

def import_csv_to_dynamodb(table_name, csv_file_name):
    dynamodb_resource = boto3.resource(
        'dynamodb', region_name=aws_region, aws_access_key_id=MY_ACCESS_KEY_ID, aws_secret_access_key=MY_SECRET_ACCESS_KEY)
    dynamodb_table = dynamodb_resource.Table(table_name)

    BATCH_COUNT = 25  # 25 is the maximum batch size for AWS DynamoDB

    items = []
    count = 0

    with open(csv_file_name, 'r') as read_obj:
        csv_reader = reader(read_obj)
        # passing the file object to reader() to get the reader object
        header = next(csv_reader)
        # Checking file as empty
        if header != None:
            for cur_row in csv_reader:
                count += 1
                id = str(generate_id())
                user_info = {"id": id, "name": cur_row[0], "email": cur_row[1],
                             "type": cur_row[2], "address": cur_row[3], "country": cur_row[4]}
                if count % BATCH_COUNT == 0:
                    print('batch write start'),
                    batch_insert(items, dynamodb_table)
                    items = []
                    print('batch done (row number: ' + str(count) + ')')

            if len(items) > 0:
                batch_insert(items, dynamodb_table)


def main():
    table_name = 'my-dynamodb-table-name-users'
    csv_file_name = 'data.csv'
    import_csv_to_dynamodb(table_name, csv_file_name)

if __name__ == "__main__":