-
Notifications
You must be signed in to change notification settings - Fork 421
/
Copy pathaws_config_rule_event.py
360 lines (281 loc) · 11.9 KB
/
aws_config_rule_event.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
from __future__ import annotations
from typing import Any
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper
def get_invoke_event(
invoking_event: dict,
) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration:
"""
Returns the corresponding event object based on the messageType in the invoking event.
Parameters
----------
invoking_event: dict
The invoking event received.
Returns
-------
AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration:
The event object based on the messageType in the invoking event.
"""
message_type = invoking_event.get("messageType")
if message_type == "ScheduledNotification":
return AWSConfigScheduledNotification(invoking_event)
if message_type == "OversizedConfigurationItemChangeNotification":
return AWSConfigOversizedConfiguration(invoking_event)
# Default return is AWSConfigConfigurationChanged event
return AWSConfigConfigurationChanged(invoking_event)
class AWSConfigConfigurationChanged(DictWrapper):
@property
def configuration_item_diff(self) -> dict:
"""The configuration item diff of the ConfigurationItemChangeNotification event."""
return self["configurationItemDiff"]
@property
def configuration_item(self) -> AWSConfigConfigurationItemChanged:
"""The configuration item of the ConfigurationItemChangeNotification event."""
return AWSConfigConfigurationItemChanged(self["configurationItem"])
@property
def raw_configuration_item(self) -> dict:
"""The raw configuration item of the ConfigurationItemChangeNotification event."""
return self["configurationItem"]
@property
def record_version(self) -> str:
"""The record version of the ConfigurationItemChangeNotification event."""
return self["recordVersion"]
@property
def message_type(self) -> str:
"""The message type of the ConfigurationItemChangeNotification event."""
return self["messageType"]
@property
def notification_creation_time(self) -> str:
"""The notification creation time of the ConfigurationItemChangeNotification event."""
return self["notificationCreationTime"]
class AWSConfigConfigurationItemChanged(DictWrapper):
@property
def related_events(self) -> list:
"""The related events of the ConfigurationItemChangeNotification event."""
return self["relatedEvents"]
@property
def relationships(self) -> list:
"""The relationships of the ConfigurationItemChangeNotification event."""
return self["relationships"]
@property
def configuration(self) -> dict:
"""The configuration of the ConfigurationItemChangeNotification event."""
return self["configuration"]
@property
def supplementary_configuration(self) -> dict:
"""The supplementary configuration of the ConfigurationItemChangeNotification event."""
return self["supplementaryConfiguration"]
@property
def tags(self) -> dict:
"""The tags of the ConfigurationItemChangeNotification event."""
return self["tags"]
@property
def configuration_item_version(self) -> str:
"""The configuration item version of the ConfigurationItemChangeNotification event."""
return self["configurationItemVersion"]
@property
def configuration_item_capture_time(self) -> str:
"""The configuration item capture time of the ConfigurationItemChangeNotification event."""
return self["configurationItemCaptureTime"]
@property
def configuration_state_id(self) -> str:
"""The configuration state id of the ConfigurationItemChangeNotification event."""
return self["configurationStateId"]
@property
def accountid(self) -> str:
"""The accountid of the ConfigurationItemChangeNotification event."""
return self["awsAccountId"]
@property
def configuration_item_status(self) -> str:
"""The configuration item status of the ConfigurationItemChangeNotification event."""
return self["configurationItemStatus"]
@property
def resource_type(self) -> str:
"""The resource type of the ConfigurationItemChangeNotification event."""
return self["resourceType"]
@property
def resource_id(self) -> str:
"""The resource id of the ConfigurationItemChangeNotification event."""
return self["resourceId"]
@property
def resource_name(self) -> str:
"""The resource name of the ConfigurationItemChangeNotification event."""
return self["resourceName"]
@property
def resource_arn(self) -> str:
"""The resource arn of the ConfigurationItemChangeNotification event."""
return self["ARN"]
@property
def region(self) -> str:
"""The region of the ConfigurationItemChangeNotification event."""
return self["awsRegion"]
@property
def availability_zone(self) -> str:
"""The availability zone of the ConfigurationItemChangeNotification event."""
return self["availabilityZone"]
@property
def configuration_state_md5_hash(self) -> str:
"""The md5 hash of the state of the ConfigurationItemChangeNotification event."""
return self["configurationStateMd5Hash"]
@property
def resource_creation_time(self) -> str:
"""The resource creation time of the ConfigurationItemChangeNotification event."""
return self["resourceCreationTime"]
class AWSConfigScheduledNotification(DictWrapper):
@property
def accountid(self) -> str:
"""The accountid of the ScheduledNotification event."""
return self["awsAccountId"]
@property
def notification_creation_time(self) -> str:
"""The notification creation time of the ScheduledNotification event."""
return self["notificationCreationTime"]
@property
def record_version(self) -> str:
"""The record version of the ScheduledNotification event."""
return self["recordVersion"]
@property
def message_type(self) -> str:
"""The message type of the ScheduledNotification event."""
return self["messageType"]
class AWSConfigOversizedConfiguration(DictWrapper):
@property
def configuration_item_summary(self) -> AWSConfigOversizedConfigurationItemSummary:
"""The configuration item summary of the OversizedConfiguration event."""
return AWSConfigOversizedConfigurationItemSummary(self["configurationItemSummary"])
@property
def raw_configuration_item_summary(self) -> str:
"""The raw configuration item summary of the OversizedConfiguration event."""
return self["configurationItemSummary"]
@property
def message_type(self) -> str:
"""The message type of the OversizedConfiguration event."""
return self["messageType"]
@property
def notification_creation_time(self) -> str:
"""The notification creation time of the OversizedConfiguration event."""
return self["notificationCreationTime"]
@property
def record_version(self) -> str:
"""The record version of the OversizedConfiguration event."""
return self["recordVersion"]
class AWSConfigOversizedConfigurationItemSummary(DictWrapper):
@property
def change_type(self) -> str:
"""The change type of the OversizedConfiguration event."""
return self["changeType"]
@property
def configuration_item_version(self) -> str:
"""The configuration item version of the OversizedConfiguration event."""
return self["configurationItemVersion"]
@property
def configuration_item_capture_time(self) -> str:
"""The configuration item capture time of the OversizedConfiguration event."""
return self["configurationItemCaptureTime"]
@property
def configuration_state_id(self) -> str:
"""The configuration state id of the OversizedConfiguration event."""
return self["configurationStateId"]
@property
def accountid(self) -> str:
"""The accountid of the OversizedConfiguration event."""
return self["awsAccountId"]
@property
def configuration_item_status(self) -> str:
"""The configuration item status of the OversizedConfiguration event."""
return self["configurationItemStatus"]
@property
def resource_type(self) -> str:
"""The resource type of the OversizedConfiguration event."""
return self["resourceType"]
@property
def resource_id(self) -> str:
"""The resource id of the OversizedConfiguration event."""
return self["resourceId"]
@property
def resource_name(self) -> str:
"""The resource name of the OversizedConfiguration event."""
return self["resourceName"]
@property
def resource_arn(self) -> str:
"""The resource arn of the OversizedConfiguration event."""
return self["ARN"]
@property
def region(self) -> str:
"""The region of the OversizedConfiguration event."""
return self["awsRegion"]
@property
def availability_zone(self) -> str:
"""The availability zone of the OversizedConfiguration event."""
return self["availabilityZone"]
@property
def configuration_state_md5_hash(self) -> str:
"""The state md5 hash of the OversizedConfiguration event."""
return self["configurationStateMd5Hash"]
@property
def resource_creation_time(self) -> str:
"""The resource creation time of the OversizedConfiguration event."""
return self["resourceCreationTime"]
class AWSConfigRuleEvent(DictWrapper):
"""Events for AWS Config Rules
Documentation:
--------------
- https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules_lambda-functions.html
"""
def __init__(self, data: dict[str, Any]):
super().__init__(data)
self._invoking_event: Any | None = None
self._rule_parameters: Any | None = None
@property
def version(self) -> str:
"""The version of the event."""
return self["version"]
@property
def invoking_event(
self,
) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration:
"""The invoking payload of the event."""
if self._invoking_event is None:
self._invoking_event = self._json_deserializer(self["invokingEvent"])
return get_invoke_event(self._invoking_event)
@property
def raw_invoking_event(self) -> str:
"""The raw invoking payload of the event."""
return self["invokingEvent"]
@property
def rule_parameters(self) -> dict:
"""The parameters of the event."""
if self._rule_parameters is None:
self._rule_parameters = self._json_deserializer(self["ruleParameters"])
return self._rule_parameters
@property
def result_token(self) -> str:
"""The result token of the event."""
return self["resultToken"]
@property
def event_left_scope(self) -> bool:
"""The left scope of the event."""
return self["eventLeftScope"]
@property
def execution_role_arn(self) -> str:
"""The execution role arn of the event."""
return self["executionRoleArn"]
@property
def config_rule_arn(self) -> str:
"""The arn of the rule of the event."""
return self["configRuleArn"]
@property
def config_rule_name(self) -> str:
"""The name of the rule of the event."""
return self["configRuleName"]
@property
def config_rule_id(self) -> str:
"""The id of the rule of the event."""
return self["configRuleId"]
@property
def accountid(self) -> str:
"""The accountid of the event."""
return self["accountId"]
@property
def evalution_mode(self) -> str | None:
"""The evalution mode of the event."""
return self.get("evaluationMode")