forked from croque-scp/notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
44 lines (37 loc) · 1.34 KB
/
Copy pathlambda_function.py
File metadata and controls
44 lines (37 loc) · 1.34 KB
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
import logging
from notifier.config.local import read_local_auth, read_local_config
from notifier.main import main
# AWS Lambda runtime attaches a default handler with formatting I don't like
# - remove it
rootLogger = logging.getLogger()
if rootLogger.handlers:
for handler in rootLogger.handlers:
rootLogger.removeHandler(handler)
# Add my own formatter
logging.basicConfig(
format="%(asctime)s - %(name)s:%(lineno)s - %(levelname)s - %(message)s",
level=logging.DEBUG,
)
logger = logging.getLogger(__name__)
def lambda_handler(event, context):
"""Handler for an AWS Lambda.
:param event: A list of config paths. First item is the path to the
main config, second item is the path to the authentication config. This
must be set in the EventBridge event as a JSON constant.
"""
logger.info("Starting Lambda")
print("Handler received event:", event)
del context
if not isinstance(event, list):
raise ValueError("Event should be a list of configs")
if not len(event) == 2:
raise ValueError("Config list should contain 2 items")
local_config_path, local_auth_path = event
logger.debug("Lambda: starting main procedure")
main(
read_local_config(local_config_path),
read_local_auth(local_auth_path),
[],
)
logger.info("Lambda finished")
return 0