modmex-lambda 0.6.0__py3-none-any.whl → 0.6.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- modmex_lambda/stream/events/s3.py +81 -1
- modmex_lambda/stream/flavors/schedule.py +34 -1
- {modmex_lambda-0.6.0.dist-info → modmex_lambda-0.6.2.dist-info}/METADATA +5 -1
- {modmex_lambda-0.6.0.dist-info → modmex_lambda-0.6.2.dist-info}/RECORD +6 -6
- {modmex_lambda-0.6.0.dist-info → modmex_lambda-0.6.2.dist-info}/WHEEL +0 -0
- {modmex_lambda-0.6.0.dist-info → modmex_lambda-0.6.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import json
|
|
2
2
|
import pydash
|
|
3
3
|
from pydash import get
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
'from_s3',
|
|
8
|
+
'from_sqs_eventbridge_s3',
|
|
9
|
+
'from_sqs_sns_s3',
|
|
10
|
+
'to_s3_records',
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
|
|
5
14
|
def from_s3(event):
|
|
6
15
|
return pydash.map_(
|
|
7
16
|
event['Records'],
|
|
@@ -15,6 +24,69 @@ def from_s3(event):
|
|
|
15
24
|
}
|
|
16
25
|
)
|
|
17
26
|
|
|
27
|
+
def from_sqs_sns_s3(event):
|
|
28
|
+
"""Normalize an S3 notification delivered through SNS and SQS.
|
|
29
|
+
|
|
30
|
+
An SNS message can contain more than one S3 record, so this function
|
|
31
|
+
returns one UOW per S3 record. The event contract is the same as
|
|
32
|
+
:func:`from_s3`; the transport envelopes are retained in ``record``.
|
|
33
|
+
"""
|
|
34
|
+
return pydash._(event['Records']).map(
|
|
35
|
+
lambda sqs_record: _from_sqs_record(sqs_record)
|
|
36
|
+
).flatten().value()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def from_sqs_eventbridge_s3(event):
|
|
40
|
+
"""Normalize an S3 EventBridge notification delivered through SQS."""
|
|
41
|
+
return pydash._(event['Records']).map(
|
|
42
|
+
lambda sqs_record: _from_sqs_eventbridge_record(sqs_record)
|
|
43
|
+
).flatten().value()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _from_sqs_eventbridge_record(sqs_record):
|
|
47
|
+
eventbridge_record = json.loads(sqs_record['body'])
|
|
48
|
+
detail = eventbridge_record['detail']
|
|
49
|
+
s3_record = {
|
|
50
|
+
**eventbridge_record,
|
|
51
|
+
'eventName': _eventbridge_s3_event_name(eventbridge_record),
|
|
52
|
+
's3': detail,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return pydash.map_(from_s3({'Records': [s3_record]}), lambda uow: {
|
|
56
|
+
**uow,
|
|
57
|
+
'record': {
|
|
58
|
+
'sqs': sqs_record,
|
|
59
|
+
'eventbridge': eventbridge_record,
|
|
60
|
+
's3': uow['record'],
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _eventbridge_s3_event_name(eventbridge_record):
|
|
66
|
+
detail_type = eventbridge_record.get('detail-type', '')
|
|
67
|
+
if detail_type.startswith('Object Created'):
|
|
68
|
+
return 'ObjectCreated:Put'
|
|
69
|
+
if detail_type.startswith('Object Deleted'):
|
|
70
|
+
return 'ObjectCreated:Delete'
|
|
71
|
+
return detail_type
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _from_sqs_record(sqs_record):
|
|
75
|
+
sns_record = json.loads(sqs_record['body'])
|
|
76
|
+
s3_event = json.loads(sns_record['Message'])
|
|
77
|
+
|
|
78
|
+
return pydash.map_(
|
|
79
|
+
from_s3(s3_event),
|
|
80
|
+
lambda uow: {
|
|
81
|
+
**uow,
|
|
82
|
+
'record': {
|
|
83
|
+
'sqs': sqs_record,
|
|
84
|
+
'sns': sns_record,
|
|
85
|
+
's3': uow['record'],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
)
|
|
89
|
+
|
|
18
90
|
def _calculate_event_type_prefix(record):
|
|
19
91
|
if record['eventName'] in ['ObjectCreated:Post','ObjectCreated:Put']:
|
|
20
92
|
return 'object-created'
|
|
@@ -64,3 +136,11 @@ def to_s3_records(notifications):
|
|
|
64
136
|
for i,n in enumerate(notifications)
|
|
65
137
|
]
|
|
66
138
|
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
__all__ = [
|
|
142
|
+
'from_s3',
|
|
143
|
+
'from_sqs_sns_s3',
|
|
144
|
+
'from_sqs_eventbridge_s3',
|
|
145
|
+
'to_s3_records',
|
|
146
|
+
]
|
|
@@ -3,6 +3,7 @@ import os
|
|
|
3
3
|
from datetime import datetime, timedelta, timezone
|
|
4
4
|
from typing import Any, Callable, Optional
|
|
5
5
|
|
|
6
|
+
from pydash import get
|
|
6
7
|
from reactivex import Observable, operators as ops
|
|
7
8
|
|
|
8
9
|
from modmex_lambda.connectors.ieventbridge import IEventBridgeConnector
|
|
@@ -47,7 +48,15 @@ class Schedule(BaseFlavor):
|
|
|
47
48
|
logger=logger,
|
|
48
49
|
connector=connector,
|
|
49
50
|
dependency_resolver=dependency_resolver,
|
|
50
|
-
publisher_options=
|
|
51
|
+
publisher_options={
|
|
52
|
+
**(publisher_options or {}),
|
|
53
|
+
"event_field": "emit",
|
|
54
|
+
**(
|
|
55
|
+
{"source": rule["source"]}
|
|
56
|
+
if isinstance(rule.get("source"), str)
|
|
57
|
+
else {}
|
|
58
|
+
),
|
|
59
|
+
},
|
|
51
60
|
)
|
|
52
61
|
self.rule = rule
|
|
53
62
|
|
|
@@ -57,14 +66,31 @@ class Schedule(BaseFlavor):
|
|
|
57
66
|
|
|
58
67
|
def __call__(self, source: Observable):
|
|
59
68
|
return source.pipe(
|
|
69
|
+
try_filter(self._for_collected_events),
|
|
70
|
+
try_map(self._normalize),
|
|
60
71
|
try_filter(on_event_type(self.rule)),
|
|
61
72
|
ops.do_action(print_start(self.logger)),
|
|
62
73
|
try_filter(on_content(self.rule)),
|
|
63
74
|
try_map(faulty(self._to_schedule_request)),
|
|
64
75
|
self.scheduler_ops,
|
|
76
|
+
self.publisher,
|
|
65
77
|
ops.do_action(print_end(self.logger)),
|
|
66
78
|
)
|
|
67
79
|
|
|
80
|
+
@staticmethod
|
|
81
|
+
def _for_collected_events(uow: Uow) -> bool:
|
|
82
|
+
return (
|
|
83
|
+
get(uow, "record.eventName") == "INSERT"
|
|
84
|
+
and get(uow, "record.dynamodb.Keys.sk.S") == "EVENT"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
@staticmethod
|
|
88
|
+
def _normalize(uow: Uow) -> Uow:
|
|
89
|
+
return {
|
|
90
|
+
**uow,
|
|
91
|
+
"event": get(uow, "event.raw.new.event"),
|
|
92
|
+
}
|
|
93
|
+
|
|
68
94
|
def _to_schedule_request(self, uow: Uow) -> Uow:
|
|
69
95
|
schedule_at = self._resolve_schedule_at(uow)
|
|
70
96
|
if schedule_at.tzinfo is None:
|
|
@@ -79,9 +105,16 @@ class Schedule(BaseFlavor):
|
|
|
79
105
|
raise ValueError("bus_arn or BUS_ARN is required.")
|
|
80
106
|
if not role_arn:
|
|
81
107
|
raise ValueError("role_arn or SCHEDULER_ROLE_ARN is required.")
|
|
108
|
+
if schedule_at <= datetime.now(timezone.utc):
|
|
109
|
+
return {
|
|
110
|
+
**uow,
|
|
111
|
+
"scheduled_event": scheduled_event,
|
|
112
|
+
"emit": scheduled_event,
|
|
113
|
+
}
|
|
82
114
|
return {
|
|
83
115
|
**uow,
|
|
84
116
|
"scheduled_event": scheduled_event,
|
|
117
|
+
"emit": None,
|
|
85
118
|
"schedule_request": {
|
|
86
119
|
"Name": self._value("schedule_name", uow),
|
|
87
120
|
"GroupName": self._value("group_name", uow, "default"),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modmex-lambda
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.2
|
|
4
4
|
Summary: Ultra-lightweight AWS Lambda utilities for API Gateway routing and event handling.
|
|
5
5
|
Author: Modmex
|
|
6
6
|
License: MIT
|
|
@@ -1188,6 +1188,10 @@ Use `schedule_at` when the deadline is already an explicit, timezone-aware
|
|
|
1188
1188
|
is calculated from the source event's millisecond `timestamp`, not from Lambda
|
|
1189
1189
|
processing time. Declare exactly one of those fields.
|
|
1190
1190
|
|
|
1191
|
+
If the calculated deadline has already passed when the source event is
|
|
1192
|
+
processed, `Schedule` does not create an invalid `at(...)` schedule. It
|
|
1193
|
+
publishes the deferred domain event immediately on the configured bus instead.
|
|
1194
|
+
|
|
1191
1195
|
### Event Hub
|
|
1192
1196
|
|
|
1193
1197
|
EventBridge is a natural hub for domain events. Flavors like
|
|
@@ -77,7 +77,7 @@ modmex_lambda/stream/schedulers.py,sha256=A_wFD1e7CGFGO6--QHln8Eho08fdH5W-OVWfho
|
|
|
77
77
|
modmex_lambda/stream/events/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
78
78
|
modmex_lambda/stream/events/dynamodb.py,sha256=T1g9j4QpWC1gBYaFm11YdcQ9Ma0konHIVF48mOAD_PE,4895
|
|
79
79
|
modmex_lambda/stream/events/kinesis.py,sha256=BDSO7mwAV6utXROBxbyv36fbNspwOkHpvnysmFNDz0Q,1154
|
|
80
|
-
modmex_lambda/stream/events/s3.py,sha256=
|
|
80
|
+
modmex_lambda/stream/events/s3.py,sha256=618h_xKpkA_6OfXzjVii3QwJWJUjqMn_FeMG2hoqit0,4417
|
|
81
81
|
modmex_lambda/stream/events/sns.py,sha256=MHtLaKKYvmhPOQjqCMgxNFXpBuYfW4wGaC1BxwWTaIw,2073
|
|
82
82
|
modmex_lambda/stream/events/sqs.py,sha256=AnaIdTJA5emzPKMXG-8OQTmhmB6PrGu4zXDepcHqxNE,1470
|
|
83
83
|
modmex_lambda/stream/filters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -96,7 +96,7 @@ modmex_lambda/stream/flavors/iflavor.py,sha256=KuaYO0koDCo9C8wV0nW1MV9XwZF1tvulj
|
|
|
96
96
|
modmex_lambda/stream/flavors/job.py,sha256=enIBW5A-c-bnpzL8f6vPLfr_HbQu4ucgc_YJ08vb7FM,10155
|
|
97
97
|
modmex_lambda/stream/flavors/materialize.py,sha256=-00aBf7L_egPbMzUBXAleiRVWlUQT6hbrDvL9yZrwxI,2335
|
|
98
98
|
modmex_lambda/stream/flavors/s3.py,sha256=08PzZetQFZJsiEmHf6aBJXTh8FKMFJk8Ruoqojh-NvE,2133
|
|
99
|
-
modmex_lambda/stream/flavors/schedule.py,sha256=
|
|
99
|
+
modmex_lambda/stream/flavors/schedule.py,sha256=ykfEZXbCNtI6LjK99oBLRZMZXQXBX_NIydunt1By1SE,7392
|
|
100
100
|
modmex_lambda/stream/flavors/sns.py,sha256=L-yRQFYzstdj53Dspn6EC_YLX-gvjfQCLLfbmE9zsHI,2009
|
|
101
101
|
modmex_lambda/stream/flavors/task.py,sha256=PhRMLh4oCXv2jWw-ZoeZ8ioA40Ju9e5szcnWsBayai4,4265
|
|
102
102
|
modmex_lambda/stream/flavors/update.py,sha256=QUhkXKAD18w5GT2OKcCKnkYySJyX5ao4llil-AZVLJI,6141
|
|
@@ -144,7 +144,7 @@ modmex_lambda/stream/utils/time.py,sha256=dnsL2xeWpa1FXm2p8y9rWXtICMBlCBkgLaJ_en
|
|
|
144
144
|
modmex_lambda/stream/utils/uow.py,sha256=8WSPVE7AiHInkFDfBEeKOvdirY6GAgBoS7qkF1f1JVM,3207
|
|
145
145
|
modmex_lambda/stream/utils/data_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
146
146
|
modmex_lambda/stream/utils/data_classes/dynamodb.py,sha256=h_7MtUyRkvvV1r2QECrRDu7RR4Hh94SwSjc_8K2_XGM,363
|
|
147
|
-
modmex_lambda-0.6.
|
|
148
|
-
modmex_lambda-0.6.
|
|
149
|
-
modmex_lambda-0.6.
|
|
150
|
-
modmex_lambda-0.6.
|
|
147
|
+
modmex_lambda-0.6.2.dist-info/METADATA,sha256=vHq4XiLw3MfkwjyqYeg1yyHqBbrBLqJD1ZDBgDjR93Q,35443
|
|
148
|
+
modmex_lambda-0.6.2.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
149
|
+
modmex_lambda-0.6.2.dist-info/licenses/LICENSE,sha256=_C2TDTOsYeJvE4vn9VB51laKvleBKbdNnn96wJVtXhQ,1063
|
|
150
|
+
modmex_lambda-0.6.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|