trying to insert records from CSV file to dynamodb but not getting inserted

0

Hi , i try to insert just two records from csv file to DynamoDB the below is the python code

    with open(csv_file_path, 'r') as csvfile:
          csvreader = csv.reader(csvfile)

           header = next(csvreader)
            try:
                for row in csvreader:
                  # Construct an item for DynamoDB
                   item = {header[i]: row[i] for i in range(len(header))}
                  # Insert the item into DynamoDB
                   table.put_item(Item=item)

                  print("Data inserted into DynamoDB table.")
             except Exception as e:
                          print(f"Error: {e}")

i am not getting any exception while executing the code it successfully executed but the records are not inserted in dynamodb I dont know how to debug this code from db perspective is there any logs which helps how to fix this issue please help.

keyanke
asked 2 months ago103 views
2 Answers
0

I can't see too much wrong with the code and I would absolutely expect an exception to be raised if there was something causing an error.

One thing to check is that the header[i] value for each item matches the primary key as defined in the DynamoDB table. It should be it's worth looking at.

profile pictureAWS
EXPERT
answered 2 months ago
0

print("Data has been inserted into the DynamoDB table.")
Is this message being displayed?

If for some reason there are 0 records retrieved from the CSV file, no error will occur, but no items will be added.

profile picture
danishi
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions