7
7
# Initialize a session using Amazon Kinesis
8
8
kinesis_client = boto3 .client ('kinesis' , region_name = 'ca-central-1' )
9
9
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
+
10
16
# Function to generate a random transaction
11
17
def generate_random_transaction (transaction_id ):
12
18
user_ids = ["U56789" , "U12345" , "U67890" , "U98765" ]
@@ -16,7 +22,7 @@ def generate_random_transaction(transaction_id):
16
22
statuses = ["approved" , "declined" ]
17
23
18
24
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
20
26
"user_id" : random .choice (user_ids ),
21
27
"timestamp" : (datetime .utcnow () - timedelta (seconds = random .randint (0 , 3600 ))).isoformat () + 'Z' ,
22
28
"amount" : round (random .uniform (1.0 , 1000.0 ), 2 ),
@@ -36,8 +42,7 @@ def send_transaction_to_kinesis(transaction, stream_name):
36
42
response = kinesis_client .put_record (
37
43
StreamName = stream_name ,
38
44
Data = data ,
39
- PartitionKey = partition_key ,
40
- StreamARN = "arn:aws:kinesis:ca-central-1:294331937131:stream/294331937131-kinesis-stream"
45
+ PartitionKey = partition_key
41
46
)
42
47
return response
43
48
0 commit comments