Skip to content
This repository was archived by the owner on Jul 20, 2022. It is now read-only.

Capturing data change in Aurora Blog Post #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions aws-blog-aurora-cdc/RDS_Data_Generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python
import MySQLdb
import random
import datetime

db = MySQLdb.connect(host="AURORA_CNAME",
user="DBUSER",
passwd="DBPASSWORD",
db="DB")

states = ("AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN",
"IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ",
"NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA",
"WA","WV","WI","WY")

shipping_types = ("Free", "3-Day", "2-Day")

product_categories = ("Garden", "Kitchen", "Office", "Household")
referrals = ("Other", "Friend/Colleague", "Repeat Customer", "Online Ad")

for i in range(0,10):
item_id = random.randint(1,100)
state = states[random.randint(0,len(states)-1)]
shipping_type = shipping_types[random.randint(0,len(shipping_types)-1)]
product_category = product_categories[random.randint(0,len(product_categories)-1)]
quantity = random.randint(1,4)
referral = referrals[random.randint(0,len(referrals)-1)]
price = random.randint(1,100)
order_date = datetime.date(2016,random.randint(1,12),random.randint(1,30)).isoformat()

data_order = (item_id, product_category, price, quantity, order_date, state,
shipping_type, referral)

add_order = ("INSERT INTO Sales "
"(ItemID, Category, Price, Quantity, OrderDate, DestinationState, \
ShippingType, Referral) "
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s)")

cursor = db.cursor()
cursor.execute(add_order, data_order)

db.commit()

cursor.close()
db.close()
23 changes: 23 additions & 0 deletions aws-blog-aurora-cdc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Capturing data change in aurora and visualizing data in QuickSight
This code generates sample data in a MySQL database table.

## Prerequisites
- Amazon Web Services account
- [AWS Command Line Interface (CLI)]
- Python 3.5+
- Python MySQLdb


### Running example
You can run the example my replacing the variable for Database connection in the python script with your database details. You will need
- Database CName
- Database User
- Database Password
- Database Name
You can also change the number of records the script generates.

Running the script:
```
python RDS_Data_Generator.py
```
[AWS Command Line Interface (CLI)]:http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html