-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
main.py
55 lines (43 loc) · 1.46 KB
/
main.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import logging
LOG = logging.getLogger(__name__)
def default_handler(event, context):
print("value1 = " + event["key1"])
print("value2 = " + event["key2"])
print("value3 = " + event["key3"])
return {
"message": f'{event["key1"]} {event["key3"]}'
}
def custom_env_var_echo_handler(event, context):
return os.environ.get("CustomEnvVar")
def echo_client_context_data(event, context):
custom_dict = context.client_context.custom
return custom_dict
def write_to_stderr(event, context):
LOG.error("Lambda Function is writing to stderr")
return "wrote to stderr"
def echo_event(event, context):
return event
def raise_exception(event, context):
raise Exception("Lambda is raising an exception")
def stock_transaction_recommender(event, context):
stock_price = int(event["stock_price"])
balance = event["balance"]
qty = event["qty"]
if qty*stock_price < 100:
stock_action = "Buy"
else:
stock_action = "Sell"
return {"stock_price": stock_price, "action": stock_action, "balance": balance, "qty": qty}
def stock_buyer(event, context):
current_balance = event["balance"]
new_balance = current_balance - (event["qty"]*event["stock_price"])
return {
"balance": new_balance
}
def stock_seller(event, context):
current_balance = event["balance"]
new_balance = current_balance + (event["qty"]*event["stock_price"])
return {
"balance": new_balance
}