-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_helper_lib.py
More file actions
77 lines (64 loc) · 3.27 KB
/
lambda_helper_lib.py
File metadata and controls
77 lines (64 loc) · 3.27 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def context_to_str(context):
context_str = '_Context:_\n'
context_str += '```'
context_str += 'context.function_name:' + context.function_name + '\n'
context_str += 'context.function_version:' + context.function_version + '\n'
context_str += 'context.invoked_function_arn:' + context.invoked_function_arn + '\n'
context_str += 'context.memory_limit_in_mb:' + context.memory_limit_in_mb + '\n'
context_str += 'context.aws_request_id:' + context.aws_request_id + '\n'
context_str += 'context.log_group_name:' + context.log_group_name + '\n'
context_str += 'context.log_stream_name:' + context.log_stream_name + '\n'
if (context.identity is not None):
context_str += 'context.identity.cognito_identity_id:' + safe_get(context.identity.cognito_identity_id) + '\n'
context_str += 'context.identity.cognito_identity_pool_id:' + safe_get \
(context.identity.cognito_identity_pool_id) + '\n'
else:
context_str += 'context.identity:--None--\n'
if (context.client_context is not None):
context_str += 'context.client_context.client.installation_id:' + context.client_context.client.installation_id + '\n'
context_str += 'context.client_context.client.app_title:' + context.client_context.client.app_title + '\n'
context_str += 'context.client_context.client.app_version_name:' + context.client_context.client.app_version_name + '\n'
context_str += 'context.client_context.client.app_version_code:' + context.client_context.client.app_version_code + '\n'
context_str += 'context.client_context.client.app_package_name:' + context.client_context.client.app_package_name + '\n'
context_str += 'context.client_context.custom:' + str(context.client_context.custom) + '\n'
context_str += 'context.client_context.env:' + str(context.client_context.env) + '\n'
else:
context_str += 'context.client_context:--None--\n'
context_str += 'context.get_remaining_time_in_millis:' + str(context.get_remaining_time_in_millis()) + '\n'
context_str += '```'
return context_str
def context_property_iterator(context):
context_str = '{'
if (context is not None and isinstance(context, dict) and context.__dict__):
for attr, value in context.__dict__.iteritems():
if isinstance(value, (str, int, basestring)):
context_str += '"' + str(attr or "") + '"'
context_str += ': '
context_str += '"' + str(value or "") + '",'
#context_str += '\n'
else:
# context_str += context_property_iterator(value)
context_str += 'FOO'
context_str += '}'
return context_str
def event_to_str(event):
event_str = '_Event:_\n'
event_str += '```'
try:
event_str += 'batteryVoltage:' + event['batteryVoltage'] + '\n'
event_str += 'serialNumber:' + event['serialNumber'] + '\n'
event_str += 'clickType:' + event['clickType'] + '\n'
except KeyError:
event_str += '--test event--\n'
event_str += '```'
return event_str
def is_real_event(event):
if 'clickType' in event:
return True
else:
return False
def safe_get(item):
if (item is not None):
return item
else:
return '--None--'