-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
32 lines (27 loc) · 801 Bytes
/
Copy pathlambda_function.py
File metadata and controls
32 lines (27 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import json
import boto3
import random
import datetime
s3 = boto3.client('s3')
BUCKET_NAME = 'your-s3-bucket-name'
def lambda_handler(event, context):
# 1. Generate Demo Data
products = ['Laptop', 'Mouse', 'Keyboard', 'Monitor']
data = {
'order_id': random.randint(1000, 9999),
'product': random.choice(products),
'price': random.randint(20, 500),
'date': datetime.datetime.now().isoformat()
}
# 2. Define File Name (it is unique based on time)
file_name = f"sales_data_{data['order_id']}.json"
# 3. Save to S3 bucket
s3.put_object(
Bucket=BUCKET_NAME,
Key=file_name,
Body=json.dumps(data)
)
return {
'statusCode': 200,
'body': json.dumps(f"Saved {file_name} to S3")
}