Skip to content

Commit c562aeb

Browse files
committed
add events with faulty transaction id
1 parent 7f2baad commit c562aeb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

utils/simulate_events.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
# Initialize a session using Amazon Kinesis
88
kinesis_client = boto3.client('kinesis', region_name='ca-central-1')
99

10+
def choose_transaction_id(transaction_id):
11+
return random.choice([
12+
f"T{datetime.now().strftime('%Y%m%d%H%M%S')}{transaction_id:05}",
13+
f"corrupted{datetime.now().strftime('%Y%m%d%H%M%S')}{transaction_id:05}"
14+
])
15+
1016
# Function to generate a random transaction
1117
def generate_random_transaction(transaction_id):
1218
user_ids = ["U56789", "U12345", "U67890", "U98765"]
@@ -16,7 +22,7 @@ def generate_random_transaction(transaction_id):
1622
statuses = ["approved", "declined"]
1723

1824
transaction = {
19-
"transaction_id": f"T{datetime.now().strftime('%Y%m%d%H%M%S')}{transaction_id:05}", # Combination of timestamp and incrementing number
25+
"transaction_id": choose_transaction_id(transaction_id) , # Combination of timestamp and incrementing number
2026
"user_id": random.choice(user_ids),
2127
"timestamp": (datetime.utcnow() - timedelta(seconds=random.randint(0, 3600))).isoformat() + 'Z',
2228
"amount": round(random.uniform(1.0, 1000.0), 2),
@@ -36,8 +42,7 @@ def send_transaction_to_kinesis(transaction, stream_name):
3642
response = kinesis_client.put_record(
3743
StreamName=stream_name,
3844
Data=data,
39-
PartitionKey=partition_key,
40-
StreamARN="arn:aws:kinesis:ca-central-1:294331937131:stream/294331937131-kinesis-stream"
45+
PartitionKey=partition_key
4146
)
4247
return response
4348

0 commit comments

Comments
 (0)