in workflow1_endpointbuilder/sam-app/functions/function5_createcsv/index.py [0:0]
def create_csv(datetime_id, bucket_name):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(f'DatasetCSVTable_{datetime_id}_{bucket_name}_')
scan_kwargs = {
'ProjectionExpression': "#cls, #txt",
'ExpressionAttributeNames': {"#cls": "class", "#txt": "text"}
}
f = StringIO()
writer = csv.writer(f)
done = False
start_key = None
while not done:
if start_key:
scan_kwargs['ExclusiveStartKey'] = start_key
response = table.scan(**scan_kwargs)
documents = response.get('Items', [])
for doc in documents:
writer.writerow([doc['class'], doc['text']])
start_key = response.get('LastEvaluatedKey', None)
done = start_key is None
return f