Hi Team, I am using Below Mentioned Python Script to Move CSV File Data into DynamoDB Table.
Same Python Script with same CSV data in VS code working fine but While Invoking it in UiPath in b/w it is Throwing this type of errors.Is that a problem of Python Invoke? Hopefully waiting for a solution!
import boto3
import csv
def dynamoExtract(DummyTable, csvFile, aws_access_key_id, aws_secret_access_key, region):
# Create a DynamoDB client
dynamodb = boto3.resource(‘dynamodb’, aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
region_name=region)
# Select the table to add items to
table = dynamodb.Table(DummyTable)
# Open the CSV file
with open(csvFile, 'r', encoding='utf-8') as csvfile:
# Create a CSV reader
reader = csv.DictReader(csvfile)
# Get the column names from the CSV file
fieldnames = reader.fieldnames
# Initialize an empty list for batch items
batch_items = []
# Initialize a variable to store the last successful batch
last_successful_batch = None
# Iterate over the rows in the CSV file
try:
for row in reader:
# Add each row to the batch items list as a new item
item = {}
for fieldname in fieldnames:
item[fieldname] = row[fieldname]
batch_items.append(item)
# Write the current batch to the table
with table.batch_writer() as batch:
for item in batch_items:
batch.put_item(Item=item)
# Set the last successful batch to the current batch
last_successful_batch = batch_items
# Clear the batch items list for the next batch
batch_items = []
except Exception as e:
# Return the last successful batch if an exception occurs
if last_successful_batch:
return last_successful_batch
else:
return None
# Get the total count of rows written to DynamoDB
total_rows_written = len(last_successful_batch) if last_successful_batch is not None else 0
return total_rows_written
dynamoExtract(‘AppNew’,‘G:\Athul\Filtered CSV File\Test\VisitData1.csv’,‘Secret key’,‘Secret Id’,‘Region’)
[Error screen shot it attached]