From 4d58c5d9bc548b91db87a95b6c93354464a3d928 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 17 Feb 2025 16:00:14 +0100 Subject: [PATCH 01/24] Comment out fields to work with --- .../data_classes/iot_registry_event.py | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 aws_lambda_powertools/utilities/data_classes/iot_registry_event.py diff --git a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py new file mode 100644 index 00000000000..cb63469c965 --- /dev/null +++ b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py @@ -0,0 +1,132 @@ +from datetime import datetime +from typing import Any, Dict, List, Literal, Optional + +from aws_lambda_powertools.utilities.data_classes.common import DictWrapper + +EVENT_CRUD_OPERATION = Literal["CREATED", "UPDATED", "DELETED"] +EVENT_ADD_REMOVE_OPERATION = Literal["ADDED", "REMOVED"] + +# TODO convert these to event source models and inherit from DictWrapper + + +class IoTCoreRegistryEventsBase(DictWrapper): + # event_id: str = Field(..., alias="eventId") + # timestamp: datetime + ... + + +class IoTCoreThingEvent(DictWrapper): + """ + Thing Created/Updated/Deleted + + The registry publishes event messages when things are created, updated, or deleted. + """ + + # event_type: Literal["THING_EVENT"] = Field(..., alias="eventType") + # operation: EVENT_CRUD_OPERATION + # thing_id: str = Field(..., alias="thingId") + # account_id: str = Field(..., alias="accountId") + # thing_name: str = Field(..., alias="thingName") + # version_number: int = Field(..., alias="versionNumber") + # thing_type_name: Optional[str] = Field(None, alias="thingTypeName") + # attributes: Dict[str, Any] + + +class IoTCoreThingTypeEvent(DictWrapper): + """ + Thing Type Created/Updated/Deprecated/Undeprecated/Deleted + The registry publishes event messages when thing types are created, updated, deprecated, undeprecated, or deleted. + + Format: + $aws/events/thingType/thingTypeName/created + $aws/events/thingType/thingTypeName/updated + $aws/events/thingType/thingTypeName/deleted + """ + + # event_type: Literal["THING_TYPE_EVENT"] = Field(..., alias="eventType") + # operation: EVENT_CRUD_OPERATION + # account_id: str = Field(..., alias="accountId") + # thing_type_id: str = Field(..., alias="thingTypeId") + # thing_type_name: str = Field(..., alias="thingTypeName") + # is_deprecated: bool = Field(..., alias="isDeprecated") + # deprecation_date: Optional[datetime] = Field(None, alias="deprecationDate") + # searchable_attributes: List[str] = Field(..., alias="searchableAttributes") + # propagating_attributes: List[Dict[str, str]] = Field(..., alias="propagatingAttributes") + # description: str + + +class IoTCoreThingTypeAssociationEvent(DictWrapper): + """ + The registry publishes event messages when a thing type is associated or disassociated with a thing. + + Format: + $aws/events/thingTypeAssociation/thing/thingName/thingType/typeName/added + $aws/events/thingTypeAssociation/thing/thingName/thingType/typeName/removed + """ + + # event_type: Literal["THING_TYPE_ASSOCIATION_EVENT"] = Field(..., alias="eventType") + # operation: EVENT_ADD_REMOVE_OPERATION + # thing_id: str = Field(..., alias="thingId") + # thing_name: str = Field(..., alias="thingName") + # thing_type_name: str = Field(..., alias="thingTypeName") + + +class IoTCoreThingGroupEvent(DictWrapper): + """ + The registry publishes the following event messages when a thing group is created, updated, or deleted. + + Format: + $aws/events/thingGroup/groupName/created + $aws/events/thingGroup/groupName/updated + $aws/events/thingGroup/groupName/deleted + """ + + # event_type: Literal["THING_GROUP_EVENT"] = Field(..., alias="eventType") + # operation: EVENT_CRUD_OPERATION + # account_id: str = Field(..., alias="accountId") + # thing_group_id: str = Field(..., alias="thingGroupId") + # thing_group_name: str = Field(..., alias="thingGroupName") + # version_number: int = Field(..., alias="versionNumber") + # parent_group_name: Optional[str] = Field(None, alias="parentGroupName") + # parent_group_id: Optional[str] = Field(None, alias="parentGroupId") + # description: str + # root_to_parent_thing_groups: List[Dict[str, str]] = Field(..., alias="rootToParentThingGroups") + # attributes: Dict[str, Any] + # dynamic_group_mapping_id: Optional[str] = Field(None, alias="dynamicGroupMappingId") + + +class IoTCoreAddOrRemoveFromThingGroupEvent(DictWrapper): + """ + The registry publishes event messages when a thing is added to or removed from a thing group. + + Format: + $aws/events/thingGroupMembership/thingGroup/thingGroupName/thing/thingName/added + $aws/events/thingGroupMembership/thingGroup/thingGroupName/thing/thingName/removed + """ + + # event_type: Literal["THING_GROUP_MEMBERSHIP_EVENT"] = Field(..., alias="eventType") + # operation: EVENT_ADD_REMOVE_OPERATION + # account_id: str = Field(..., alias="accountId") + # group_arn: str = Field(..., alias="groupArn") + # group_id: str = Field(..., alias="groupId") + # thing_arn: str = Field(..., alias="thingArn") + # thing_id: str = Field(..., alias="thingId") + # membership_id: str = Field(..., alias="membershipId") + + +class IoTCoreAddOrDeleteFromThingGroupEvent(DictWrapper): + """ + The registry publishes event messages when a thing group is added to or removed from another thing group. + + Format: + $aws/events/thingGroupHierarchy/thingGroup/parentThingGroupName/childThingGroup/childThingGroupName/added + $aws/events/thingGroupHierarchy/thingGroup/parentThingGroupName/childThingGroup/childThingGroupName/removed + """ + + # event_type: Literal["THING_GROUP_HIERARCHY_EVENT"] = Field(..., alias="eventType") + # operation: EVENT_ADD_REMOVE_OPERATION + # account_id: str = Field(..., alias="accountId") + # thing_group_id: str = Field(..., alias="thingGroupId") + # thing_group_name: str = Field(..., alias="thingGroupName") + # child_group_id: str = Field(..., alias="childGroupId") + # child_group_name: str = Field(..., alias="childGroupName") From 0d6a615b9904b7665efb0bb6328ee9b5a32bad67 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Tue, 18 Feb 2025 22:19:37 +0100 Subject: [PATCH 02/24] work on tests --- .../data_classes/iot_registry_event.py | 283 +++++++++++++----- .../test_iot_registry_events.py | 82 +++++ 2 files changed, 296 insertions(+), 69 deletions(-) create mode 100644 tests/unit/data_classes/required_dependencies/test_iot_registry_events.py diff --git a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py index cb63469c965..e0d4f51f6a3 100644 --- a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py +++ b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from typing import Any, Dict, List, Literal, Optional @@ -6,33 +8,63 @@ EVENT_CRUD_OPERATION = Literal["CREATED", "UPDATED", "DELETED"] EVENT_ADD_REMOVE_OPERATION = Literal["ADDED", "REMOVED"] -# TODO convert these to event source models and inherit from DictWrapper - class IoTCoreRegistryEventsBase(DictWrapper): - # event_id: str = Field(..., alias="eventId") - # timestamp: datetime - ... + @property + def event_id(self) -> str: + return self["eventId"] + @property + def timestamp(self) -> datetime: + """ + A Unix timestamp can be in seconds or milliseconds. If the value is 10 digits long, it's in seconds. + If it's 13 digits long, it's in milliseconds and should be divided by 1000 to convert it to seconds. + """ + ts = self["timestamp"] + return datetime.fromtimestamp(ts / 1000 if ts > 10**10 else ts) -class IoTCoreThingEvent(DictWrapper): + +class IoTCoreThingEvent(IoTCoreRegistryEventsBase): """ Thing Created/Updated/Deleted The registry publishes event messages when things are created, updated, or deleted. """ - # event_type: Literal["THING_EVENT"] = Field(..., alias="eventType") - # operation: EVENT_CRUD_OPERATION - # thing_id: str = Field(..., alias="thingId") - # account_id: str = Field(..., alias="accountId") - # thing_name: str = Field(..., alias="thingName") - # version_number: int = Field(..., alias="versionNumber") - # thing_type_name: Optional[str] = Field(None, alias="thingTypeName") - # attributes: Dict[str, Any] + @property + def event_type(self) -> Literal["THING_EVENT"]: + return self["eventType"] + + @property + def operation(self) -> str: + return self["operation"] + + @property + def thing_id(self) -> str: + return self["thingId"] + + @property + def account_id(self) -> str: + return self["accountId"] + + @property + def thing_name(self) -> str: + return self["thingName"] + @property + def version_number(self) -> int: + return self["versionNumber"] -class IoTCoreThingTypeEvent(DictWrapper): + @property + def thing_type_name(self) -> Optional[str]: + return self.get("thingTypeName") + + @property + def attributes(self) -> Dict[str, Any]: + return self["attributes"] + + +class IoTCoreThingTypeEvent(IoTCoreRegistryEventsBase): """ Thing Type Created/Updated/Deprecated/Undeprecated/Deleted The registry publishes event messages when thing types are created, updated, deprecated, undeprecated, or deleted. @@ -43,19 +75,48 @@ class IoTCoreThingTypeEvent(DictWrapper): $aws/events/thingType/thingTypeName/deleted """ - # event_type: Literal["THING_TYPE_EVENT"] = Field(..., alias="eventType") - # operation: EVENT_CRUD_OPERATION - # account_id: str = Field(..., alias="accountId") - # thing_type_id: str = Field(..., alias="thingTypeId") - # thing_type_name: str = Field(..., alias="thingTypeName") - # is_deprecated: bool = Field(..., alias="isDeprecated") - # deprecation_date: Optional[datetime] = Field(None, alias="deprecationDate") - # searchable_attributes: List[str] = Field(..., alias="searchableAttributes") - # propagating_attributes: List[Dict[str, str]] = Field(..., alias="propagatingAttributes") - # description: str + @property + def event_type(self) -> str: + return self["eventType"] + + @property + def operation(self) -> EVENT_CRUD_OPERATION: + return self["operation"] + + @property + def account_id(self) -> str: + return self["accountId"] + + @property + def thing_type_id(self) -> str: + return self["thingTypeId"] + @property + def thing_type_name(self) -> str: + return self["thingTypeName"] -class IoTCoreThingTypeAssociationEvent(DictWrapper): + @property + def is_deprecated(self) -> bool: + return self["isDeprecated"] + + @property + def deprecation_date(self) -> Optional[datetime]: + return datetime.fromisoformat(self["deprecationDate"]) if self.get("deprecationDate") else None + + @property + def searchable_attributes(self) -> List[str]: + return self["searchableAttributes"] + + @property + def propagating_attributes(self) -> List[Dict[str, str]]: + return self["propagatingAttributes"] + + @property + def description(self) -> str: + return self["description"] + + +class IoTCoreThingTypeAssociationEvent(IoTCoreRegistryEventsBase): """ The registry publishes event messages when a thing type is associated or disassociated with a thing. @@ -64,14 +125,28 @@ class IoTCoreThingTypeAssociationEvent(DictWrapper): $aws/events/thingTypeAssociation/thing/thingName/thingType/typeName/removed """ - # event_type: Literal["THING_TYPE_ASSOCIATION_EVENT"] = Field(..., alias="eventType") - # operation: EVENT_ADD_REMOVE_OPERATION - # thing_id: str = Field(..., alias="thingId") - # thing_name: str = Field(..., alias="thingName") - # thing_type_name: str = Field(..., alias="thingTypeName") + @property + def event_type(self) -> str: + return self["eventType"] + @property + def operation(self) -> Literal["THING_TYPE_ASSOCIATION_EVENT"]: + return self["operation"] -class IoTCoreThingGroupEvent(DictWrapper): + @property + def thing_id(self) -> str: + return self["thingId"] + + @property + def thing_name(self) -> str: + return self["thingName"] + + @property + def thing_type_name(self) -> str: + return self["thingTypeName"] + + +class IoTCoreThingGroupEvent(IoTCoreRegistryEventsBase): """ The registry publishes the following event messages when a thing group is created, updated, or deleted. @@ -81,21 +156,56 @@ class IoTCoreThingGroupEvent(DictWrapper): $aws/events/thingGroup/groupName/deleted """ - # event_type: Literal["THING_GROUP_EVENT"] = Field(..., alias="eventType") - # operation: EVENT_CRUD_OPERATION - # account_id: str = Field(..., alias="accountId") - # thing_group_id: str = Field(..., alias="thingGroupId") - # thing_group_name: str = Field(..., alias="thingGroupName") - # version_number: int = Field(..., alias="versionNumber") - # parent_group_name: Optional[str] = Field(None, alias="parentGroupName") - # parent_group_id: Optional[str] = Field(None, alias="parentGroupId") - # description: str - # root_to_parent_thing_groups: List[Dict[str, str]] = Field(..., alias="rootToParentThingGroups") - # attributes: Dict[str, Any] - # dynamic_group_mapping_id: Optional[str] = Field(None, alias="dynamicGroupMappingId") - - -class IoTCoreAddOrRemoveFromThingGroupEvent(DictWrapper): + @property + def event_type(self) -> str: + return self["eventType"] + + @property + def operation(self) -> EVENT_CRUD_OPERATION: + return self["operation"] + + @property + def account_id(self) -> str: + return self["accountId"] + + @property + def thing_group_id(self) -> str: + return self["thingGroupId"] + + @property + def thing_group_name(self) -> str: + return self["thingGroupName"] + + @property + def version_number(self) -> int: + return self["versionNumber"] + + @property + def parent_group_name(self) -> Optional[str]: + return self.get("parentGroupName") + + @property + def parent_group_id(self) -> Optional[str]: + return self.get("parentGroupId") + + @property + def description(self) -> str: + return self["description"] + + @property + def root_to_parent_thing_groups(self) -> List[Dict[str, str]]: + return self["rootToParentThingGroups"] + + @property + def attributes(self) -> Dict[str, Any]: + return self["attributes"] + + @property + def dynamic_group_mapping_id(self) -> Optional[str]: + return self.get("dynamicGroupMappingId") + + +class IoTCoreAddOrRemoveFromThingGroupEvent(IoTCoreRegistryEventsBase): """ The registry publishes event messages when a thing is added to or removed from a thing group. @@ -104,29 +214,64 @@ class IoTCoreAddOrRemoveFromThingGroupEvent(DictWrapper): $aws/events/thingGroupMembership/thingGroup/thingGroupName/thing/thingName/removed """ - # event_type: Literal["THING_GROUP_MEMBERSHIP_EVENT"] = Field(..., alias="eventType") - # operation: EVENT_ADD_REMOVE_OPERATION - # account_id: str = Field(..., alias="accountId") - # group_arn: str = Field(..., alias="groupArn") - # group_id: str = Field(..., alias="groupId") - # thing_arn: str = Field(..., alias="thingArn") - # thing_id: str = Field(..., alias="thingId") - # membership_id: str = Field(..., alias="membershipId") + @property + def event_type(self) -> str: + return self["eventType"] + @property + def operation(self) -> EVENT_ADD_REMOVE_OPERATION: + return self["operation"] -class IoTCoreAddOrDeleteFromThingGroupEvent(DictWrapper): - """ - The registry publishes event messages when a thing group is added to or removed from another thing group. + @property + def account_id(self) -> str: + return self["accountId"] - Format: - $aws/events/thingGroupHierarchy/thingGroup/parentThingGroupName/childThingGroup/childThingGroupName/added - $aws/events/thingGroupHierarchy/thingGroup/parentThingGroupName/childThingGroup/childThingGroupName/removed - """ + @property + def group_arn(self) -> str: + return self["groupArn"] + + @property + def group_id(self) -> str: + return self["groupId"] + + @property + def thing_arn(self) -> str: + return self["thingArn"] + + @property + def thing_id(self) -> str: + return self["thingId"] + + @property + def membership_id(self) -> str: + return self["membershipId"] + + +class IoTCoreAddOrDeleteFromThingGroupEvent(IoTCoreRegistryEventsBase): + @property + def event_type(self) -> str: + return self["eventType"] + + @property + def operation(self) -> EVENT_ADD_REMOVE_OPERATION: + return self["operation"] + + @property + def account_id(self) -> str: + return self["accountId"] + + @property + def thing_group_id(self) -> str: + return self["thingGroupId"] + + @property + def thing_group_name(self) -> str: + return self["thingGroupName"] + + @property + def child_group_id(self) -> str: + return self["childGroupId"] - # event_type: Literal["THING_GROUP_HIERARCHY_EVENT"] = Field(..., alias="eventType") - # operation: EVENT_ADD_REMOVE_OPERATION - # account_id: str = Field(..., alias="accountId") - # thing_group_id: str = Field(..., alias="thingGroupId") - # thing_group_name: str = Field(..., alias="thingGroupName") - # child_group_id: str = Field(..., alias="childGroupId") - # child_group_name: str = Field(..., alias="childGroupName") + @property + def child_group_name(self) -> str: + return self["childGroupName"] diff --git a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py new file mode 100644 index 00000000000..f66c134a6d4 --- /dev/null +++ b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py @@ -0,0 +1,82 @@ +from datetime import datetime + +from aws_lambda_powertools.utilities.data_classes.iot_registry_event import ( + IoTCoreAddOrDeleteFromThingGroupEvent, + IoTCoreAddOrRemoveFromThingGroupEvent, + IoTCoreThingEvent, + IoTCoreThingGroupEvent, + IoTCoreThingTypeAssociationEvent, + IoTCoreThingTypeEvent, +) +from tests.functional.utils import load_event + + +def test_iotcore_thing_event(): + raw_event = load_event("iotRegistryEventsThingEvent.json") + parsed_event = IoTCoreThingEvent(raw_event) + + assert parsed_event.event_type == raw_event["eventType"] + assert parsed_event.operation == raw_event["operation"] + assert parsed_event.thing_id == raw_event["thingId"] + assert parsed_event.account_id == raw_event["accountId"] + assert parsed_event.thing_name == raw_event["thingName"] + assert parsed_event.version_number == raw_event["versionNumber"] + assert parsed_event.thing_type_name == raw_event.get("thingTypeName") + assert parsed_event.attributes == raw_event["attributes"] + assert parsed_event.event_id == raw_event["eventId"] + + # Validate timestamp conversion + expected_timestamp = datetime.fromtimestamp( + raw_event["timestamp"] / 1000 if raw_event["timestamp"] > 10**10 else raw_event["timestamp"], + ) + assert parsed_event.timestamp == expected_timestamp + + +def test_iotcore_thing_type_event(): + raw_event = load_event("iotRegistryEventsThingTypeEvent.json") + parsed_event = IoTCoreThingTypeEvent(raw_event) + + assert parsed_event.event_id == raw_event["eventId"] + assert parsed_event.thing_type_name == raw_event["thingTypeName"] + + +def test_iotcore_thing_type_association_event(): + raw_event = load_event("iotRegistryEventsThingTypeAssociationEvent.json") + parsed_event = IoTCoreThingTypeAssociationEvent(raw_event) + + assert parsed_event.event_id == raw_event["eventId"] + assert parsed_event.thing_id == raw_event["thingId"] + assert parsed_event.thing_type_name == raw_event["thingTypeName"] + + +def test_iotcore_thing_group_event(): + raw_event = load_event("iotRegistryEventsThingGroupEvent.json") + parsed_event = IoTCoreThingGroupEvent(raw_event) + + assert parsed_event.event_id == raw_event["eventId"] + assert parsed_event.thing_group_name == raw_event["thingGroupName"] + + +def test_iotcore_add_or_remove_from_thing_group_event(): + raw_event = load_event("iotRegistryEventsAddOrRemoveFromThingGroupEvent.json") + parsed_event = IoTCoreAddOrRemoveFromThingGroupEvent(raw_event) + + assert parsed_event.event_id == raw_event["eventId"] + assert parsed_event.group_id == raw_event["groupId"] + + +def test_iotcore_add_or_delete_from_thing_group_event(): + raw_event = load_event("iotRegistryEventsAddOrDeleteFromThingGroupEvent.json") + parsed_event = IoTCoreAddOrDeleteFromThingGroupEvent(raw_event) + + assert parsed_event.event_id == raw_event["eventId"] + assert parsed_event.thing_group_id == raw_event["thingGroupId"] + assert parsed_event.thing_group_name == raw_event["thingGroupName"] + assert parsed_event.child_group_id == raw_event["childGroupId"] + assert parsed_event.child_group_name == raw_event["childGroupName"] + assert parsed_event.operation == raw_event["operation"] + + expected_timestamp = datetime.fromtimestamp( + raw_event["timestamp"] / 1000 if raw_event["timestamp"] > 10**10 else raw_event["timestamp"], + ) + assert parsed_event.timestamp == expected_timestamp From 7b18d1014774540f86293c62d399efe50217d7cc Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Tue, 18 Feb 2025 22:26:10 +0100 Subject: [PATCH 03/24] Add docs --- .../data_classes/iot_registry_event.py | 185 +++++++++++++++--- 1 file changed, 163 insertions(+), 22 deletions(-) diff --git a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py index e0d4f51f6a3..533a3c0fdbb 100644 --- a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py +++ b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py @@ -12,13 +12,19 @@ class IoTCoreRegistryEventsBase(DictWrapper): @property def event_id(self) -> str: + """ + The unique identifier for the event. + """ return self["eventId"] @property def timestamp(self) -> datetime: """ - A Unix timestamp can be in seconds or milliseconds. If the value is 10 digits long, it's in seconds. - If it's 13 digits long, it's in milliseconds and should be divided by 1000 to convert it to seconds. + The timestamp of the event. + + The timestamp is in Unix format (seconds or milliseconds). + If it's 10 digits long, it represents seconds; + if it's 13 digits, it's in milliseconds and is converted to seconds. """ ts = self["timestamp"] return datetime.fromtimestamp(ts / 1000 if ts > 10**10 else ts) @@ -27,40 +33,63 @@ def timestamp(self) -> datetime: class IoTCoreThingEvent(IoTCoreRegistryEventsBase): """ Thing Created/Updated/Deleted - The registry publishes event messages when things are created, updated, or deleted. """ @property def event_type(self) -> Literal["THING_EVENT"]: + """ + The event type, which will always be "THING_EVENT". + """ return self["eventType"] @property def operation(self) -> str: + """ + The operation type for the event (e.g., CREATED, UPDATED, DELETED). + """ return self["operation"] @property def thing_id(self) -> str: + """ + The unique identifier for the thing. + """ return self["thingId"] @property def account_id(self) -> str: + """ + The account ID associated with the event. + """ return self["accountId"] @property def thing_name(self) -> str: + """ + The name of the thing. + """ return self["thingName"] @property def version_number(self) -> int: + """ + The version number of the thing. + """ return self["versionNumber"] @property def thing_type_name(self) -> Optional[str]: + """ + The thing type name if available, or None if not specified. + """ return self.get("thingTypeName") @property def attributes(self) -> Dict[str, Any]: + """ + The dictionary of attributes associated with the thing. + """ return self["attributes"] @@ -68,210 +97,322 @@ class IoTCoreThingTypeEvent(IoTCoreRegistryEventsBase): """ Thing Type Created/Updated/Deprecated/Undeprecated/Deleted The registry publishes event messages when thing types are created, updated, deprecated, undeprecated, or deleted. - - Format: - $aws/events/thingType/thingTypeName/created - $aws/events/thingType/thingTypeName/updated - $aws/events/thingType/thingTypeName/deleted """ @property def event_type(self) -> str: + """ + The event type, corresponding to a thing type event. + """ return self["eventType"] @property def operation(self) -> EVENT_CRUD_OPERATION: + """ + The operation performed on the thing type (e.g., CREATED, UPDATED, DELETED). + """ return self["operation"] @property def account_id(self) -> str: + """ + The account ID associated with the event. + """ return self["accountId"] @property def thing_type_id(self) -> str: + """ + The unique identifier for the thing type. + """ return self["thingTypeId"] @property def thing_type_name(self) -> str: + """ + The name of the thing type. + """ return self["thingTypeName"] @property def is_deprecated(self) -> bool: + """ + Whether the thing type is marked as deprecated. + """ return self["isDeprecated"] @property def deprecation_date(self) -> Optional[datetime]: + """ + The deprecation date of the thing type, or None if not available. + """ return datetime.fromisoformat(self["deprecationDate"]) if self.get("deprecationDate") else None @property def searchable_attributes(self) -> List[str]: + """ + The list of attributes that are searchable for the thing type. + """ return self["searchableAttributes"] @property def propagating_attributes(self) -> List[Dict[str, str]]: + """ + The list of attributes to propagate for the thing type. + """ return self["propagatingAttributes"] @property def description(self) -> str: + """ + The description of the thing type. + """ return self["description"] class IoTCoreThingTypeAssociationEvent(IoTCoreRegistryEventsBase): """ The registry publishes event messages when a thing type is associated or disassociated with a thing. - - Format: - $aws/events/thingTypeAssociation/thing/thingName/thingType/typeName/added - $aws/events/thingTypeAssociation/thing/thingName/thingType/typeName/removed """ @property def event_type(self) -> str: + """ + The event type, related to the thing type association event. + """ return self["eventType"] @property def operation(self) -> Literal["THING_TYPE_ASSOCIATION_EVENT"]: + """ + The operation type, which is always "THING_TYPE_ASSOCIATION_EVENT". + """ return self["operation"] @property def thing_id(self) -> str: + """ + The unique identifier for the associated thing. + """ return self["thingId"] @property def thing_name(self) -> str: + """ + The name of the associated thing. + """ return self["thingName"] @property def thing_type_name(self) -> str: + """ + The name of the associated thing type. + """ return self["thingTypeName"] class IoTCoreThingGroupEvent(IoTCoreRegistryEventsBase): """ - The registry publishes the following event messages when a thing group is created, updated, or deleted. - - Format: - $aws/events/thingGroup/groupName/created - $aws/events/thingGroup/groupName/updated - $aws/events/thingGroup/groupName/deleted + The registry publishes event messages when a thing group is created, updated, or deleted. """ @property def event_type(self) -> str: + """ + The event type, corresponding to the thing group event. + """ return self["eventType"] @property def operation(self) -> EVENT_CRUD_OPERATION: + """ + The operation type (e.g., CREATED, UPDATED, DELETED) performed on the thing group. + """ return self["operation"] @property def account_id(self) -> str: + """ + The account ID associated with the event. + """ return self["accountId"] @property def thing_group_id(self) -> str: + """ + The unique identifier for the thing group. + """ return self["thingGroupId"] @property def thing_group_name(self) -> str: + """ + The name of the thing group. + """ return self["thingGroupName"] @property def version_number(self) -> int: + """ + The version number of the thing group. + """ return self["versionNumber"] @property def parent_group_name(self) -> Optional[str]: + """ + The name of the parent group, or None if not applicable. + """ return self.get("parentGroupName") @property def parent_group_id(self) -> Optional[str]: + """ + The ID of the parent group, or None if not applicable. + """ return self.get("parentGroupId") @property def description(self) -> str: + """ + The description of the thing group. + """ return self["description"] @property def root_to_parent_thing_groups(self) -> List[Dict[str, str]]: + """ + The list of root-to-parent thing group mappings. + """ return self["rootToParentThingGroups"] @property def attributes(self) -> Dict[str, Any]: + """ + The attributes associated with the thing group. + """ return self["attributes"] @property def dynamic_group_mapping_id(self) -> Optional[str]: + """ + The dynamic group mapping ID if available, or None if not specified. + """ return self.get("dynamicGroupMappingId") class IoTCoreAddOrRemoveFromThingGroupEvent(IoTCoreRegistryEventsBase): """ The registry publishes event messages when a thing is added to or removed from a thing group. - - Format: - $aws/events/thingGroupMembership/thingGroup/thingGroupName/thing/thingName/added - $aws/events/thingGroupMembership/thingGroup/thingGroupName/thing/thingName/removed """ @property def event_type(self) -> str: + """ + The event type, corresponding to the add/remove from thing group event. + """ return self["eventType"] @property def operation(self) -> EVENT_ADD_REMOVE_OPERATION: + """ + The operation (ADDED or REMOVED) performed on the thing in the group. + """ return self["operation"] @property def account_id(self) -> str: + """ + The account ID associated with the event. + """ return self["accountId"] @property def group_arn(self) -> str: + """ + The ARN of the group the thing was added to or removed from. + """ return self["groupArn"] @property def group_id(self) -> str: + """ + The unique identifier of the group. + """ return self["groupId"] @property def thing_arn(self) -> str: + """ + The ARN of the thing being added or removed. + """ return self["thingArn"] @property def thing_id(self) -> str: + """ + The unique identifier for the thing being added or removed. + """ return self["thingId"] @property def membership_id(self) -> str: + """ + The unique membership ID for the thing within the group. + """ return self["membershipId"] class IoTCoreAddOrDeleteFromThingGroupEvent(IoTCoreRegistryEventsBase): + """ + The registry publishes event messages when a child group is added to or deleted from a parent group. + """ + @property def event_type(self) -> str: + """ + The event type, corresponding to the add/delete from thing group event. + """ return self["eventType"] @property def operation(self) -> EVENT_ADD_REMOVE_OPERATION: + """ + The operation (ADDED or REMOVED) performed on the child group. + """ return self["operation"] @property def account_id(self) -> str: + """ + The account ID associated with the event. + """ return self["accountId"] @property def thing_group_id(self) -> str: + """ + The unique identifier of the thing group. + """ return self["thingGroupId"] @property def thing_group_name(self) -> str: + """ + The name of the thing group. + """ return self["thingGroupName"] @property def child_group_id(self) -> str: + """ + The unique identifier of the child group being added or removed. + """ return self["childGroupId"] @property def child_group_name(self) -> str: + """ + The name of the child group being added or removed. + """ return self["childGroupName"] From 5e6655a02e20cf76b457c5c7c32c1fd3409b4227 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Wed, 19 Feb 2025 10:11:41 +0100 Subject: [PATCH 04/24] Add initial doc links --- docs/utilities/data_classes.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 57bd2584ae5..f6ac026edc3 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -102,6 +102,12 @@ Each event source is linked to its corresponding GitHub file with the full set o | [TransferFamilyAuthorizerResponse] | `TransferFamilyAuthorizerResponse` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/transfer_family_event.py) | | [VPC Lattice V2](#vpc-lattice-v2) | `VPCLatticeV2Event` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/vpc_lattice.py) | | [VPC Lattice V1](#vpc-lattice-v1) | `VPCLatticeEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/vpc_lattice.py) | +| IoT Core Thing Created/Updated/Deleted | [`IoTCoreThingEvent`](#iotcorethingevent) | [GitHub](https://github.com/example/repo) | +| IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted | [`IoTCoreThingTypeEvent`](#iotcorethingtypeevent) | [GitHub](https://github.com/example/repo) | +| IoT Core Thing Type Associated/Disassociated with a Thing | [`IoTCoreThingTypeAssociationEvent`](#iotcorethingtypeassociationevent) | [GitHub](https://github.com/example/repo) | +| IoT Core Thing Group Created/Updated/Deleted | [`IoTCoreThingGroupEvent`](#iotcorethinggroupevent) | [GitHub](https://github.com/example/repo) | +| IoT Thing Added/Removed from Thing Group | [`IoTCoreAddOrRemoveFromThingGroupEvent`](#iotcoreaddorremovefromthinggroupevent) | [GitHub](https://github.com/example/repo) | +| IoT Child Group Added/Deleted from Parent Group | [`IoTCoreAddOrDeleteFromThingGroupEvent`](#iotcoreaddordeletefromthinggroupevent) | [GitHub](https://github.com/example/repo) | ???+ info The examples showcase a subset of Event Source Data Classes capabilities - for comprehensive details, leverage your IDE's From 9b63aedcfcdbafc7736f35e8b476eb50c1215bb7 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Wed, 19 Feb 2025 10:13:30 +0100 Subject: [PATCH 05/24] work --- docs/utilities/data_classes.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index f6ac026edc3..37618b4c469 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -817,6 +817,13 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s --8<-- "examples/event_sources/events/vpc_lattice_payload.json" ``` +### IoT Core Thing Created/Updated/Deleted +### IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted +### IoT Core Thing Type Associated/Disassociated with a Thing +### IoT Core Thing Group Created/Updated/Deleted +### IoT Thing Added/Removed from Thing Group +### IoT Child Group Added/Deleted from Parent Group + ## Advanced ### Debugging From 7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Wed, 19 Feb 2025 20:26:54 +0100 Subject: [PATCH 06/24] fix links --- docs/utilities/data_classes.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 37618b4c469..f80b9ca89f1 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -102,16 +102,16 @@ Each event source is linked to its corresponding GitHub file with the full set o | [TransferFamilyAuthorizerResponse] | `TransferFamilyAuthorizerResponse` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/transfer_family_event.py) | | [VPC Lattice V2](#vpc-lattice-v2) | `VPCLatticeV2Event` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/vpc_lattice.py) | | [VPC Lattice V1](#vpc-lattice-v1) | `VPCLatticeEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/vpc_lattice.py) | -| IoT Core Thing Created/Updated/Deleted | [`IoTCoreThingEvent`](#iotcorethingevent) | [GitHub](https://github.com/example/repo) | -| IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted | [`IoTCoreThingTypeEvent`](#iotcorethingtypeevent) | [GitHub](https://github.com/example/repo) | -| IoT Core Thing Type Associated/Disassociated with a Thing | [`IoTCoreThingTypeAssociationEvent`](#iotcorethingtypeassociationevent) | [GitHub](https://github.com/example/repo) | -| IoT Core Thing Group Created/Updated/Deleted | [`IoTCoreThingGroupEvent`](#iotcorethinggroupevent) | [GitHub](https://github.com/example/repo) | -| IoT Thing Added/Removed from Thing Group | [`IoTCoreAddOrRemoveFromThingGroupEvent`](#iotcoreaddorremovefromthinggroupevent) | [GitHub](https://github.com/example/repo) | -| IoT Child Group Added/Deleted from Parent Group | [`IoTCoreAddOrDeleteFromThingGroupEvent`](#iotcoreaddordeletefromthinggroupevent) | [GitHub](https://github.com/example/repo) | +| [IoT Core Thing Created/Updated/Deleted](#iot-core-thing-createdupdateddeleted) | [`IoTCoreThingEvent`](#iotcorethingevent) | [GitHub](https://github.com/example/repo) | +| [IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted](#iot-core-thing-type-createdupdateddeprecatedundeprecateddeleted) | [`IoTCoreThingTypeEvent`](#iotcorethingtypeevent) | [GitHub](https://github.com/example/repo) | +| [IoT Core Thing Type Associated/Disassociated with a Thing](#iot-core-thing-type-associateddisassociated-with-a-thing) | [`IoTCoreThingTypeAssociationEvent`](#iotcorethingtypeassociationevent) | [GitHub](https://github.com/example/repo) | +| [IoT Core Thing Group Created/Updated/Deleted](#iot-core-thing-group-createdupdateddeleted) | [`IoTCoreThingGroupEvent`](#iotcorethinggroupevent) | [GitHub](https://github.com/example/repo) | +| [IoT Thing Added/Removed from Thing Group](#iot-thing-addedremoved-from-thing-group) | [`IoTCoreAddOrRemoveFromThingGroupEvent`](#iotcoreaddorremovefromthinggroupevent) | [GitHub](https://github.com/example/repo) | +| [IoT Child Group Added/Deleted from Parent Group](#iot-child-group-addeddeleted-from-parent-group) | [`IoTCoreAddOrDeleteFromThingGroupEvent`](#iotcoreaddordeletefromthinggroupevent) | [GitHub](https://github.com/example/repo) | ???+ info The examples showcase a subset of Event Source Data Classes capabilities - for comprehensive details, leverage your IDE's - autocompletion, refer to type hints and docstrings, and explore the [full API reference](https://docs.powertools.aws.dev/lambda/python/latest/api/utilities/data_classes/) for complete property listings of each event source. + autocompletion, refer to type https://www.apple.com/nl/shop/buy-mac/apple-studio-displayhints and docstrings, and explore the [full API reference](https://docs.powertools.aws.dev/lambda/python/latest/api/utilities/data_classes/) for complete property listings of each event source. ### Active MQ From 92cd5dad7af403efdfce422be4cc9831221fde13 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Wed, 19 Feb 2025 20:30:49 +0100 Subject: [PATCH 07/24] Add github links --- docs/utilities/data_classes.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index f80b9ca89f1..bf6af967cad 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -102,12 +102,12 @@ Each event source is linked to its corresponding GitHub file with the full set o | [TransferFamilyAuthorizerResponse] | `TransferFamilyAuthorizerResponse` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/transfer_family_event.py) | | [VPC Lattice V2](#vpc-lattice-v2) | `VPCLatticeV2Event` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/vpc_lattice.py) | | [VPC Lattice V1](#vpc-lattice-v1) | `VPCLatticeEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/vpc_lattice.py) | -| [IoT Core Thing Created/Updated/Deleted](#iot-core-thing-createdupdateddeleted) | [`IoTCoreThingEvent`](#iotcorethingevent) | [GitHub](https://github.com/example/repo) | -| [IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted](#iot-core-thing-type-createdupdateddeprecatedundeprecateddeleted) | [`IoTCoreThingTypeEvent`](#iotcorethingtypeevent) | [GitHub](https://github.com/example/repo) | -| [IoT Core Thing Type Associated/Disassociated with a Thing](#iot-core-thing-type-associateddisassociated-with-a-thing) | [`IoTCoreThingTypeAssociationEvent`](#iotcorethingtypeassociationevent) | [GitHub](https://github.com/example/repo) | -| [IoT Core Thing Group Created/Updated/Deleted](#iot-core-thing-group-createdupdateddeleted) | [`IoTCoreThingGroupEvent`](#iotcorethinggroupevent) | [GitHub](https://github.com/example/repo) | -| [IoT Thing Added/Removed from Thing Group](#iot-thing-addedremoved-from-thing-group) | [`IoTCoreAddOrRemoveFromThingGroupEvent`](#iotcoreaddorremovefromthinggroupevent) | [GitHub](https://github.com/example/repo) | -| [IoT Child Group Added/Deleted from Parent Group](#iot-child-group-addeddeleted-from-parent-group) | [`IoTCoreAddOrDeleteFromThingGroupEvent`](#iotcoreaddordeletefromthinggroupevent) | [GitHub](https://github.com/example/repo) | +| [IoT Core Thing Created/Updated/Deleted](#iot-core-thing-createdupdateddeleted) | [`IoTCoreThingEvent`](#iotcorethingevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L33) | +| [IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted](#iot-core-thing-type-createdupdateddeprecatedundeprecateddeleted) | [`IoTCoreThingTypeEvent`](#iotcorethingtypeevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L96) | +| [IoT Core Thing Type Associated/Disassociated with a Thing](#iot-core-thing-type-associateddisassociated-with-a-thing) | [`IoTCoreThingTypeAssociationEvent`](#iotcorethingtypeassociationevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L173) | +| [IoT Core Thing Group Created/Updated/Deleted](#iot-core-thing-group-createdupdateddeleted) | [`IoTCoreThingGroupEvent`](#iotcorethinggroupevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L214) | +| [IoT Thing Added/Removed from Thing Group](#iot-thing-addedremoved-from-thing-group) | [`IoTCoreAddOrRemoveFromThingGroupEvent`](#iotcoreaddorremovefromthinggroupevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L304) | +| [IoT Child Group Added/Deleted from Parent Group](#iot-child-group-addeddeleted-from-parent-group) | [`IoTCoreAddOrDeleteFromThingGroupEvent`](#iotcoreaddordeletefromthinggroupevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L366) | ???+ info The examples showcase a subset of Event Source Data Classes capabilities - for comprehensive details, leverage your IDE's From bcee331b760e76804e88c06a849568026a68b8ba Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Wed, 19 Feb 2025 20:33:05 +0100 Subject: [PATCH 08/24] work --- examples/event_sources/src/iot_registry_event.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/event_sources/src/iot_registry_event.py diff --git a/examples/event_sources/src/iot_registry_event.py b/examples/event_sources/src/iot_registry_event.py new file mode 100644 index 00000000000..eb1ae458f8e --- /dev/null +++ b/examples/event_sources/src/iot_registry_event.py @@ -0,0 +1 @@ +... From 0f95d3c447c527e7eac9bd3d6cf716af9e022668 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Thu, 20 Feb 2025 09:45:40 +0100 Subject: [PATCH 09/24] add files --- .../src/iot_registry_add_or_delete_from_thing_group_event.py | 0 .../src/iot_registry_add_or_remove_from_thing_group_event.py | 0 examples/event_sources/src/iot_registry_event.py | 1 - examples/event_sources/src/iot_registry_thing_event.py | 0 examples/event_sources/src/iot_registry_thing_group_event.py | 0 .../src/iot_registry_thing_type_association_event.py | 0 examples/event_sources/src/iot_registry_thing_type_event.py | 0 7 files changed, 1 deletion(-) create mode 100644 examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py create mode 100644 examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py delete mode 100644 examples/event_sources/src/iot_registry_event.py create mode 100644 examples/event_sources/src/iot_registry_thing_event.py create mode 100644 examples/event_sources/src/iot_registry_thing_group_event.py create mode 100644 examples/event_sources/src/iot_registry_thing_type_association_event.py create mode 100644 examples/event_sources/src/iot_registry_thing_type_event.py diff --git a/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py b/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py b/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/event_sources/src/iot_registry_event.py b/examples/event_sources/src/iot_registry_event.py deleted file mode 100644 index eb1ae458f8e..00000000000 --- a/examples/event_sources/src/iot_registry_event.py +++ /dev/null @@ -1 +0,0 @@ -... diff --git a/examples/event_sources/src/iot_registry_thing_event.py b/examples/event_sources/src/iot_registry_thing_event.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/event_sources/src/iot_registry_thing_group_event.py b/examples/event_sources/src/iot_registry_thing_group_event.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/event_sources/src/iot_registry_thing_type_association_event.py b/examples/event_sources/src/iot_registry_thing_type_association_event.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/event_sources/src/iot_registry_thing_type_event.py b/examples/event_sources/src/iot_registry_thing_type_event.py new file mode 100644 index 00000000000..e69de29bb2d From cc9f0d09c35e5d5cb0843ab539fd74df4c32128e Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Thu, 20 Feb 2025 09:55:46 +0100 Subject: [PATCH 10/24] fill classes --- .../iot_registry_add_or_delete_from_thing_group_event.py | 6 ++++++ .../iot_registry_add_or_remove_from_thing_group_event.py | 6 ++++++ examples/event_sources/src/iot_registry_thing_event.py | 6 ++++++ .../event_sources/src/iot_registry_thing_group_event.py | 6 ++++++ .../src/iot_registry_thing_type_association_event.py | 6 ++++++ examples/event_sources/src/iot_registry_thing_type_event.py | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py b/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py index e69de29bb2d..19722dd9e17 100644 --- a/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py +++ b/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py @@ -0,0 +1,6 @@ +from aws_lambda_powertools.utilities.data_classes import event_source +from aws_lambda_powertools.utilities.data_classes.iot_registry_event import IoTCoreAddOrDeleteFromThingGroupEvent + + +@event_source(data_class=IoTCoreAddOrDeleteFromThingGroupEvent) +def lambda_handler(event: IoTCoreAddOrDeleteFromThingGroupEvent, context): ... diff --git a/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py b/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py index e69de29bb2d..0c5e81df1b3 100644 --- a/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py +++ b/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py @@ -0,0 +1,6 @@ +from aws_lambda_powertools.utilities.data_classes import event_source +from aws_lambda_powertools.utilities.data_classes.iot_registry_event import IoTCoreAddOrRemoveFromThingGroupEvent + + +@event_source(data_class=IoTCoreAddOrRemoveFromThingGroupEvent) +def lambda_handler(event: IoTCoreAddOrRemoveFromThingGroupEvent, context): ... diff --git a/examples/event_sources/src/iot_registry_thing_event.py b/examples/event_sources/src/iot_registry_thing_event.py index e69de29bb2d..d37e1931a71 100644 --- a/examples/event_sources/src/iot_registry_thing_event.py +++ b/examples/event_sources/src/iot_registry_thing_event.py @@ -0,0 +1,6 @@ +from aws_lambda_powertools.utilities.data_classes import event_source +from aws_lambda_powertools.utilities.data_classes.iot_registry_event import IoTCoreThingEvent + + +@event_source(data_class=IoTCoreThingEvent) +def lambda_handler(event: IoTCoreThingEvent, context): ... diff --git a/examples/event_sources/src/iot_registry_thing_group_event.py b/examples/event_sources/src/iot_registry_thing_group_event.py index e69de29bb2d..907b68075cd 100644 --- a/examples/event_sources/src/iot_registry_thing_group_event.py +++ b/examples/event_sources/src/iot_registry_thing_group_event.py @@ -0,0 +1,6 @@ +from aws_lambda_powertools.utilities.data_classes import event_source +from aws_lambda_powertools.utilities.data_classes.iot_registry_event import IoTCoreThingGroupEvent + + +@event_source(data_class=IoTCoreThingGroupEvent) +def lambda_handler(event: IoTCoreThingGroupEvent, context): ... diff --git a/examples/event_sources/src/iot_registry_thing_type_association_event.py b/examples/event_sources/src/iot_registry_thing_type_association_event.py index e69de29bb2d..3a0f63bd19c 100644 --- a/examples/event_sources/src/iot_registry_thing_type_association_event.py +++ b/examples/event_sources/src/iot_registry_thing_type_association_event.py @@ -0,0 +1,6 @@ +from aws_lambda_powertools.utilities.data_classes import event_source +from aws_lambda_powertools.utilities.data_classes.iot_registry_event import IoTCoreThingTypeAssociationEvent + + +@event_source(data_class=IoTCoreThingTypeAssociationEvent) +def lambda_handler(event: IoTCoreThingTypeAssociationEvent, context): ... diff --git a/examples/event_sources/src/iot_registry_thing_type_event.py b/examples/event_sources/src/iot_registry_thing_type_event.py index e69de29bb2d..45fc66b4ecd 100644 --- a/examples/event_sources/src/iot_registry_thing_type_event.py +++ b/examples/event_sources/src/iot_registry_thing_type_event.py @@ -0,0 +1,6 @@ +from aws_lambda_powertools.utilities.data_classes import event_source +from aws_lambda_powertools.utilities.data_classes.iot_registry_event import IoTCoreThingTypeEvent + + +@event_source(data_class=IoTCoreThingTypeEvent) +def lambda_handler(event: IoTCoreThingTypeEvent, context): ... From 0a329478d43ab32a172ff3964b7dd38c16f122b4 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Thu, 20 Feb 2025 09:57:00 +0100 Subject: [PATCH 11/24] add log statement --- .../src/iot_registry_add_or_delete_from_thing_group_event.py | 3 ++- .../src/iot_registry_add_or_remove_from_thing_group_event.py | 3 ++- examples/event_sources/src/iot_registry_thing_event.py | 3 ++- examples/event_sources/src/iot_registry_thing_group_event.py | 3 ++- .../src/iot_registry_thing_type_association_event.py | 3 ++- examples/event_sources/src/iot_registry_thing_type_event.py | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py b/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py index 19722dd9e17..a71604cd29d 100644 --- a/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py +++ b/examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py @@ -3,4 +3,5 @@ @event_source(data_class=IoTCoreAddOrDeleteFromThingGroupEvent) -def lambda_handler(event: IoTCoreAddOrDeleteFromThingGroupEvent, context): ... +def lambda_handler(event: IoTCoreAddOrDeleteFromThingGroupEvent, context): + print(f"Received IoT Core event type {event.event_type}") diff --git a/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py b/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py index 0c5e81df1b3..bd3ca1b9ca2 100644 --- a/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py +++ b/examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py @@ -3,4 +3,5 @@ @event_source(data_class=IoTCoreAddOrRemoveFromThingGroupEvent) -def lambda_handler(event: IoTCoreAddOrRemoveFromThingGroupEvent, context): ... +def lambda_handler(event: IoTCoreAddOrRemoveFromThingGroupEvent, context): + print(f"Received IoT Core event type {event.event_type}") diff --git a/examples/event_sources/src/iot_registry_thing_event.py b/examples/event_sources/src/iot_registry_thing_event.py index d37e1931a71..00b7cd39a49 100644 --- a/examples/event_sources/src/iot_registry_thing_event.py +++ b/examples/event_sources/src/iot_registry_thing_event.py @@ -3,4 +3,5 @@ @event_source(data_class=IoTCoreThingEvent) -def lambda_handler(event: IoTCoreThingEvent, context): ... +def lambda_handler(event: IoTCoreThingEvent, context): + print(f"Received IoT Core event type {event.event_type}") diff --git a/examples/event_sources/src/iot_registry_thing_group_event.py b/examples/event_sources/src/iot_registry_thing_group_event.py index 907b68075cd..39fa69f73e5 100644 --- a/examples/event_sources/src/iot_registry_thing_group_event.py +++ b/examples/event_sources/src/iot_registry_thing_group_event.py @@ -3,4 +3,5 @@ @event_source(data_class=IoTCoreThingGroupEvent) -def lambda_handler(event: IoTCoreThingGroupEvent, context): ... +def lambda_handler(event: IoTCoreThingGroupEvent, context): + print(f"Received IoT Core event type {event.event_type}") diff --git a/examples/event_sources/src/iot_registry_thing_type_association_event.py b/examples/event_sources/src/iot_registry_thing_type_association_event.py index 3a0f63bd19c..4f47ec2754b 100644 --- a/examples/event_sources/src/iot_registry_thing_type_association_event.py +++ b/examples/event_sources/src/iot_registry_thing_type_association_event.py @@ -3,4 +3,5 @@ @event_source(data_class=IoTCoreThingTypeAssociationEvent) -def lambda_handler(event: IoTCoreThingTypeAssociationEvent, context): ... +def lambda_handler(event: IoTCoreThingTypeAssociationEvent, context): + print(f"Received IoT Core event type {event.event_type}") diff --git a/examples/event_sources/src/iot_registry_thing_type_event.py b/examples/event_sources/src/iot_registry_thing_type_event.py index 45fc66b4ecd..4d077cec000 100644 --- a/examples/event_sources/src/iot_registry_thing_type_event.py +++ b/examples/event_sources/src/iot_registry_thing_type_event.py @@ -3,4 +3,5 @@ @event_source(data_class=IoTCoreThingTypeEvent) -def lambda_handler(event: IoTCoreThingTypeEvent, context): ... +def lambda_handler(event: IoTCoreThingTypeEvent, context): + print(f"Received IoT Core event type {event.event_type}") From d0926144f72b84e25f978e7fbe7792b588b9a697 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 24 Feb 2025 22:04:19 +0100 Subject: [PATCH 12/24] work --- docs/utilities/data_classes.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index bf6af967cad..6d02b77a650 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -85,7 +85,7 @@ Each event source is linked to its corresponding GitHub file with the full set o | [Cognito User Pool](#cognito-user-pool) | Multiple available under `cognito_user_pool_event` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/cognito_user_pool_event.py) | | [Connect Contact Flow](#connect-contact-flow) | `ConnectContactFlowEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/connect_contact_flow_event.py) | | [DynamoDB streams](#dynamodb-streams) | `DynamoDBStreamEvent`, `DynamoDBRecordEventName` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/dynamo_db_stream_event.py) | -| [EventBridge](#eventbridge) | `EventBridgeEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/event_bridge_event.py) | +| [EventBridge](#eventbridge) | ****`EventBridgeEvent`**** | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/event_bridge_event.py) | | [Kafka](#kafka) | `KafkaEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/kafka_event.py) | | [Kinesis Data Stream](#kinesis-streams) | `KinesisStreamEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/kinesis_stream_event.py) | | [Kinesis Firehose Delivery Stream](#kinesis-firehose-delivery-stream) | `KinesisFirehoseEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/kinesis_firehose_event.py) | @@ -817,7 +817,20 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s --8<-- "examples/event_sources/events/vpc_lattice_payload.json" ``` -### IoT Core Thing Created/Updated/Deleted +### IoT Core Thing Created/Updated/Deleted + + +=== "app.py" + + ```python hl_lines="7-9 18" + --8<-- "examples/event_sources/src/kinesis_batch_example.py" + ``` + +=== "Example Event" + ```json + --8<-- "tests/events/kinesisStreamCloudWatchLogsEvent.json" + ``` + ### IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted ### IoT Core Thing Type Associated/Disassociated with a Thing ### IoT Core Thing Group Created/Updated/Deleted From f4d628104d950e686972be393a6cc860a0f2be0d Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 24 Feb 2025 22:05:34 +0100 Subject: [PATCH 13/24] apply suggestions --- .../data_classes/iot_registry_event.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py index 533a3c0fdbb..8f2f4faa1b5 100644 --- a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py +++ b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py @@ -1,7 +1,7 @@ from __future__ import annotations from datetime import datetime -from typing import Any, Dict, List, Literal, Optional +from typing import Any, Literal from aws_lambda_powertools.utilities.data_classes.common import DictWrapper @@ -79,14 +79,14 @@ def version_number(self) -> int: return self["versionNumber"] @property - def thing_type_name(self) -> Optional[str]: + def thing_type_name(self) -> str | None: """ The thing type name if available, or None if not specified. """ return self.get("thingTypeName") @property - def attributes(self) -> Dict[str, Any]: + def attributes(self) -> dict[str, Any]: """ The dictionary of attributes associated with the thing. """ @@ -142,7 +142,7 @@ def is_deprecated(self) -> bool: return self["isDeprecated"] @property - def deprecation_date(self) -> Optional[datetime]: + def deprecation_date(self) -> datetime | None: """ The deprecation date of the thing type, or None if not available. """ @@ -156,7 +156,7 @@ def searchable_attributes(self) -> List[str]: return self["searchableAttributes"] @property - def propagating_attributes(self) -> List[Dict[str, str]]: + def propagating_attributes(self) -> list[dict[str, str]]: """ The list of attributes to propagate for the thing type. """ @@ -259,14 +259,14 @@ def version_number(self) -> int: return self["versionNumber"] @property - def parent_group_name(self) -> Optional[str]: + def parent_group_name(self) -> str | None: """ The name of the parent group, or None if not applicable. """ return self.get("parentGroupName") @property - def parent_group_id(self) -> Optional[str]: + def parent_group_id(self) -> str | None: """ The ID of the parent group, or None if not applicable. """ @@ -280,21 +280,21 @@ def description(self) -> str: return self["description"] @property - def root_to_parent_thing_groups(self) -> List[Dict[str, str]]: + def root_to_parent_thing_groups(self) -> list[dict[str, str]]: """ The list of root-to-parent thing group mappings. """ return self["rootToParentThingGroups"] @property - def attributes(self) -> Dict[str, Any]: + def attributes(self) -> dict[str, Any]: """ The attributes associated with the thing group. """ return self["attributes"] @property - def dynamic_group_mapping_id(self) -> Optional[str]: + def dynamic_group_mapping_id(self) -> str | None: """ The dynamic group mapping ID if available, or None if not specified. """ From a727e6703d24945189604fc8dbaeec47bc0f1e22 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 24 Feb 2025 22:09:15 +0100 Subject: [PATCH 14/24] Add examples for first items --- docs/utilities/data_classes.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 6d02b77a650..335d3e51348 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -818,20 +818,27 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Core Thing Created/Updated/Deleted +=== "app.py" + ```python + --8<-- "examples/event_sources/src/iot_registry_thing_event.py" + ``` +=== "Example Event" + ```json + --8<-- "tests/events/iotRegistryEventsThingEvent.json" + ``` +### IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted === "app.py" - - ```python hl_lines="7-9 18" - --8<-- "examples/event_sources/src/kinesis_batch_example.py" + ```python + --8<-- "examples/event_sources/src/iot_registry_thing_type_event.py" ``` === "Example Event" ```json - --8<-- "tests/events/kinesisStreamCloudWatchLogsEvent.json" + --8<-- "tests/events/iotRegistryEventsThingTypeEvent.json" ``` -### IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted ### IoT Core Thing Type Associated/Disassociated with a Thing ### IoT Core Thing Group Created/Updated/Deleted ### IoT Thing Added/Removed from Thing Group From 8e26cdff5e943072092a81c38c99edb9e6574075 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 24 Feb 2025 22:11:16 +0100 Subject: [PATCH 15/24] Fix documentation --- docs/utilities/data_classes.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 335d3e51348..3fd949ef4d6 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -840,7 +840,27 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Core Thing Type Associated/Disassociated with a Thing +=== "app.py" + ```python + --8<-- "examples/event_sources/src/iot_registry_thing_type_association_event.py" + ``` + +=== "Example Event" + ```json + --8<-- "tests/events/iotRegistryEventsThingTypeAssociationEvent.json" + ``` + ### IoT Core Thing Group Created/Updated/Deleted +=== "app.py" + ```python + --8<-- "examples/event_sources/src/iot_registry_thing_group_event.py" + ``` + +=== "Example Event" + ```json + --8<-- "tests/events/iotRegistryEventsThingGroupEvent.json" + ``` + ### IoT Thing Added/Removed from Thing Group ### IoT Child Group Added/Deleted from Parent Group From 6cb994f57a1cfc77c29a7260fa028b52cd24a41b Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 24 Feb 2025 22:11:42 +0100 Subject: [PATCH 16/24] apply suggestion --- .../utilities/data_classes/iot_registry_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py index 8f2f4faa1b5..f873e2884d7 100644 --- a/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py +++ b/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py @@ -149,7 +149,7 @@ def deprecation_date(self) -> datetime | None: return datetime.fromisoformat(self["deprecationDate"]) if self.get("deprecationDate") else None @property - def searchable_attributes(self) -> List[str]: + def searchable_attributes(self) -> list[str]: """ The list of attributes that are searchable for the thing type. """ From c77c89068b6426658f06c4ceda0caa0d3953c374 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 24 Feb 2025 22:14:44 +0100 Subject: [PATCH 17/24] Add doc example --- docs/utilities/data_classes.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 3fd949ef4d6..2288ef5d4c4 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -862,6 +862,16 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Thing Added/Removed from Thing Group +=== "app.py" + ```python + --8<-- "examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py" + ``` + +=== "Example Event" + ```json + --8<-- "tests/events/iotRegistryEventsAddOrRemoveFromThingGroupEvent.json" + ``` + ### IoT Child Group Added/Deleted from Parent Group ## Advanced From d3a051173f8f19a6e0960f4d522713ecc053fd42 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 24 Feb 2025 22:16:43 +0100 Subject: [PATCH 18/24] Work --- docs/utilities/data_classes.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 2288ef5d4c4..20e26fda6fa 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -873,6 +873,15 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Child Group Added/Deleted from Parent Group +=== "app.py" + ```python + --8<-- "examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py" + ``` + +=== "Example Event" + ```json + --8<-- "tests/events/iotRegistryEventsAddOrDeleteFromThingGroupEvent.json" + ``` ## Advanced From 5c0423096e176641d38264206b9941515118d268 Mon Sep 17 00:00:00 2001 From: Bas van Driel Date: Mon, 24 Feb 2025 22:22:36 +0100 Subject: [PATCH 19/24] work --- docs/utilities/data_classes.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 20e26fda6fa..09113f10d7e 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -818,6 +818,8 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Core Thing Created/Updated/Deleted +You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thing). + === "app.py" ```python --8<-- "examples/event_sources/src/iot_registry_thing_event.py" @@ -828,7 +830,9 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s --8<-- "tests/events/iotRegistryEventsThingEvent.json" ``` -### IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted +### IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted +You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thingtype-crud). + === "app.py" ```python --8<-- "examples/event_sources/src/iot_registry_thing_type_event.py" @@ -840,6 +844,8 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Core Thing Type Associated/Disassociated with a Thing +You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thingtype-assoc). + === "app.py" ```python --8<-- "examples/event_sources/src/iot_registry_thing_type_association_event.py" @@ -851,6 +857,8 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Core Thing Group Created/Updated/Deleted +You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thinggroup-crud). + === "app.py" ```python --8<-- "examples/event_sources/src/iot_registry_thing_group_event.py" @@ -862,6 +870,8 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Thing Added/Removed from Thing Group +You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thinggroup-addremove). + === "app.py" ```python --8<-- "examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py" @@ -873,6 +883,8 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s ``` ### IoT Child Group Added/Deleted from Parent Group +You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thinggroup-adddelete). + === "app.py" ```python --8<-- "examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py" From 6751e09885d424c4783706919447008b9e998d26 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Tue, 25 Feb 2025 09:14:40 +0000 Subject: [PATCH 20/24] Adding more coverage + documentation --- docs/utilities/data_classes.md | 48 +++++++++++-------- .../test_iot_registry_events.py | 11 +++++ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 09113f10d7e..b3ba5a2f474 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -85,7 +85,7 @@ Each event source is linked to its corresponding GitHub file with the full set o | [Cognito User Pool](#cognito-user-pool) | Multiple available under `cognito_user_pool_event` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/cognito_user_pool_event.py) | | [Connect Contact Flow](#connect-contact-flow) | `ConnectContactFlowEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/connect_contact_flow_event.py) | | [DynamoDB streams](#dynamodb-streams) | `DynamoDBStreamEvent`, `DynamoDBRecordEventName` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/dynamo_db_stream_event.py) | -| [EventBridge](#eventbridge) | ****`EventBridgeEvent`**** | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/event_bridge_event.py) | +| [EventBridge](#eventbridge) | `EventBridgeEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/event_bridge_event.py) | | [Kafka](#kafka) | `KafkaEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/kafka_event.py) | | [Kinesis Data Stream](#kinesis-streams) | `KinesisStreamEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/kinesis_stream_event.py) | | [Kinesis Firehose Delivery Stream](#kinesis-firehose-delivery-stream) | `KinesisFirehoseEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/kinesis_firehose_event.py) | @@ -102,16 +102,16 @@ Each event source is linked to its corresponding GitHub file with the full set o | [TransferFamilyAuthorizerResponse] | `TransferFamilyAuthorizerResponse` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/transfer_family_event.py) | | [VPC Lattice V2](#vpc-lattice-v2) | `VPCLatticeV2Event` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/vpc_lattice.py) | | [VPC Lattice V1](#vpc-lattice-v1) | `VPCLatticeEvent` | [Github](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/vpc_lattice.py) | -| [IoT Core Thing Created/Updated/Deleted](#iot-core-thing-createdupdateddeleted) | [`IoTCoreThingEvent`](#iotcorethingevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L33) | -| [IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted](#iot-core-thing-type-createdupdateddeprecatedundeprecateddeleted) | [`IoTCoreThingTypeEvent`](#iotcorethingtypeevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L96) | -| [IoT Core Thing Type Associated/Disassociated with a Thing](#iot-core-thing-type-associateddisassociated-with-a-thing) | [`IoTCoreThingTypeAssociationEvent`](#iotcorethingtypeassociationevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L173) | -| [IoT Core Thing Group Created/Updated/Deleted](#iot-core-thing-group-createdupdateddeleted) | [`IoTCoreThingGroupEvent`](#iotcorethinggroupevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L214) | -| [IoT Thing Added/Removed from Thing Group](#iot-thing-addedremoved-from-thing-group) | [`IoTCoreAddOrRemoveFromThingGroupEvent`](#iotcoreaddorremovefromthinggroupevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L304) | -| [IoT Child Group Added/Deleted from Parent Group](#iot-child-group-addeddeleted-from-parent-group) | [`IoTCoreAddOrDeleteFromThingGroupEvent`](#iotcoreaddordeletefromthinggroupevent) | [GitHub](https://github.com/basvandriel/powertools-lambda-python/blob/7a9ebf9b15cc064c368e5e9ef55343e5dc5c676c/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L366) | +| [IoT Core Thing Created/Updated/Deleted](#iot-core-thing-createdupdateddeleted) | `IoTCoreThingEvent` | [GitHub](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L33) | +| [IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted](#iot-core-thing-type-createdupdateddeprecatedundeprecateddeleted) | `IoTCoreThingTypeEvent` | [GitHub](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L96) | +| [IoT Core Thing Type Associated/Disassociated with a Thing](#iot-core-thing-type-associateddisassociated-with-a-thing) | `IoTCoreThingTypeAssociationEvent` | [GitHub](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L173) | +| [IoT Core Thing Group Created/Updated/Deleted](#iot-core-thing-group-createdupdateddeleted) | `IoTCoreThingGroupEvent` | [GitHub](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L214) | +| [IoT Thing Added/Removed from Thing Group](#iot-thing-addedremoved-from-thing-group) | `IoTCoreAddOrRemoveFromThingGroupEvent` | [GitHub](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L304) | +| [IoT Child Group Added/Deleted from Parent Group](#iot-child-group-addeddeleted-from-parent-group) | `IoTCoreAddOrDeleteFromThingGroupEvent` | [GitHub](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/iot_registry_event.py#L366) | ???+ info The examples showcase a subset of Event Source Data Classes capabilities - for comprehensive details, leverage your IDE's - autocompletion, refer to type https://www.apple.com/nl/shop/buy-mac/apple-studio-displayhints and docstrings, and explore the [full API reference](https://docs.powertools.aws.dev/lambda/python/latest/api/utilities/data_classes/) for complete property listings of each event source. + autocompletion, refer to type hints and docstrings, and explore the [full API reference](https://docs.powertools.aws.dev/lambda/python/latest/api/utilities/data_classes/) for complete property listings of each event source. ### Active MQ @@ -817,11 +817,14 @@ You can register your Lambda functions as targets within an Amazon VPC Lattice s --8<-- "examples/event_sources/events/vpc_lattice_payload.json" ``` -### IoT Core Thing Created/Updated/Deleted +### IoT Core Events + +#### IoT Core Thing Created/Updated/Deleted + You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thing). === "app.py" - ```python + ```python hl_lines="2 5" --8<-- "examples/event_sources/src/iot_registry_thing_event.py" ``` @@ -830,11 +833,12 @@ You can use IoT Core registry events to trigger your lambda functions. More info --8<-- "tests/events/iotRegistryEventsThingEvent.json" ``` -### IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted +#### IoT Core Thing Type Created/Updated/Deprecated/Undeprecated/Deleted + You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thingtype-crud). === "app.py" - ```python + ```python hl_lines="2 5" --8<-- "examples/event_sources/src/iot_registry_thing_type_event.py" ``` @@ -843,11 +847,12 @@ You can use IoT Core registry events to trigger your lambda functions. More info --8<-- "tests/events/iotRegistryEventsThingTypeEvent.json" ``` -### IoT Core Thing Type Associated/Disassociated with a Thing +#### IoT Core Thing Type Associated/Disassociated with a Thing + You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thingtype-assoc). === "app.py" - ```python + ```python hl_lines="2 5" --8<-- "examples/event_sources/src/iot_registry_thing_type_association_event.py" ``` @@ -856,11 +861,12 @@ You can use IoT Core registry events to trigger your lambda functions. More info --8<-- "tests/events/iotRegistryEventsThingTypeAssociationEvent.json" ``` -### IoT Core Thing Group Created/Updated/Deleted +#### IoT Core Thing Group Created/Updated/Deleted + You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thinggroup-crud). === "app.py" - ```python + ```python hl_lines="2 5" --8<-- "examples/event_sources/src/iot_registry_thing_group_event.py" ``` @@ -869,11 +875,12 @@ You can use IoT Core registry events to trigger your lambda functions. More info --8<-- "tests/events/iotRegistryEventsThingGroupEvent.json" ``` -### IoT Thing Added/Removed from Thing Group +#### IoT Thing Added/Removed from Thing Group + You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thinggroup-addremove). === "app.py" - ```python + ```python hl_lines="2 5" --8<-- "examples/event_sources/src/iot_registry_add_or_remove_from_thing_group_event.py" ``` @@ -882,11 +889,12 @@ You can use IoT Core registry events to trigger your lambda functions. More info --8<-- "tests/events/iotRegistryEventsAddOrRemoveFromThingGroupEvent.json" ``` -### IoT Child Group Added/Deleted from Parent Group +#### IoT Child Group Added/Deleted from Parent Group + You can use IoT Core registry events to trigger your lambda functions. More information on this specific one can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html#registry-events-thinggroup-adddelete). === "app.py" - ```python + ```python hl_lines="2 5" --8<-- "examples/event_sources/src/iot_registry_add_or_delete_from_thing_group_event.py" ``` diff --git a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py index f66c134a6d4..8dc6e9447b4 100644 --- a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py +++ b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py @@ -36,17 +36,28 @@ def test_iotcore_thing_type_event(): raw_event = load_event("iotRegistryEventsThingTypeEvent.json") parsed_event = IoTCoreThingTypeEvent(raw_event) + assert parsed_event.event_type == raw_event["eventType"] + assert parsed_event.operation == raw_event["operation"] assert parsed_event.event_id == raw_event["eventId"] + assert parsed_event.account_id == raw_event["accountId"] assert parsed_event.thing_type_name == raw_event["thingTypeName"] + assert parsed_event.is_deprecated == raw_event["isDeprecated"] + assert parsed_event.deprecation_date == raw_event["deprecationDate"] + assert parsed_event.searchable_attributes == raw_event["searchableAttributes"] + assert parsed_event.propagating_attributes == raw_event["propagatingAttributes"] + assert parsed_event.description == raw_event["description"] def test_iotcore_thing_type_association_event(): raw_event = load_event("iotRegistryEventsThingTypeAssociationEvent.json") parsed_event = IoTCoreThingTypeAssociationEvent(raw_event) + assert parsed_event.event_type == raw_event["eventType"] + assert parsed_event.operation == raw_event["operation"] assert parsed_event.event_id == raw_event["eventId"] assert parsed_event.thing_id == raw_event["thingId"] assert parsed_event.thing_type_name == raw_event["thingTypeName"] + assert parsed_event.thing_name == raw_event["thingName"] def test_iotcore_thing_group_event(): From d79a661d7f9d9217a5e9390781bedf9ae48b5691 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Tue, 25 Feb 2025 09:27:17 +0000 Subject: [PATCH 21/24] Adding more coverage + documentation --- .../test_iot_registry_events.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py index 8dc6e9447b4..e60f784d3b0 100644 --- a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py +++ b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py @@ -46,6 +46,7 @@ def test_iotcore_thing_type_event(): assert parsed_event.searchable_attributes == raw_event["searchableAttributes"] assert parsed_event.propagating_attributes == raw_event["propagatingAttributes"] assert parsed_event.description == raw_event["description"] + assert parsed_event.thing_type_id == raw_event["thingTypeId"] def test_iotcore_thing_type_association_event(): @@ -65,22 +66,41 @@ def test_iotcore_thing_group_event(): parsed_event = IoTCoreThingGroupEvent(raw_event) assert parsed_event.event_id == raw_event["eventId"] + assert parsed_event.operation == raw_event["operation"] + assert parsed_event.account_id == raw_event["accountId"] assert parsed_event.thing_group_name == raw_event["thingGroupName"] + assert parsed_event.thing_group_id == raw_event["thingGroupId"] + assert parsed_event.version_number == raw_event["versionNumber"] + assert parsed_event.parent_group_name == raw_event["parentGroupName"] + assert parsed_event.parent_group_id == raw_event["parentGroupId"] + assert parsed_event.description == raw_event["description"] + assert parsed_event.root_to_parent_thing_groups == raw_event["rootToParentThingGroups"] + assert parsed_event.attributes == raw_event["attributes"] + assert parsed_event.dynamic_group_mapping_id == raw_event["dynamicGroupMappingId"] def test_iotcore_add_or_remove_from_thing_group_event(): raw_event = load_event("iotRegistryEventsAddOrRemoveFromThingGroupEvent.json") parsed_event = IoTCoreAddOrRemoveFromThingGroupEvent(raw_event) + assert parsed_event.event_type == raw_event["eventType"] + assert parsed_event.operation == raw_event["operation"] + assert parsed_event.account_id == raw_event["accountId"] assert parsed_event.event_id == raw_event["eventId"] assert parsed_event.group_id == raw_event["groupId"] + assert parsed_event.group_arn == raw_event["groupArn"] + assert parsed_event.thing_arn == raw_event["thingArn"] + assert parsed_event.thing_id == raw_event["thingId"] + assert parsed_event.membership_id == raw_event["membershipId"] def test_iotcore_add_or_delete_from_thing_group_event(): raw_event = load_event("iotRegistryEventsAddOrDeleteFromThingGroupEvent.json") parsed_event = IoTCoreAddOrDeleteFromThingGroupEvent(raw_event) + assert parsed_event.event_type == raw_event["eventType"] assert parsed_event.event_id == raw_event["eventId"] + assert parsed_event.account_id == raw_event["accountId"] assert parsed_event.thing_group_id == raw_event["thingGroupId"] assert parsed_event.thing_group_name == raw_event["thingGroupName"] assert parsed_event.child_group_id == raw_event["childGroupId"] From 958be8822c0ee921054eb62437bee07227b84601 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Tue, 25 Feb 2025 09:44:23 +0000 Subject: [PATCH 22/24] Adding more coverage + documentation --- .../required_dependencies/test_iot_registry_events.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py index e60f784d3b0..0efc36a947f 100644 --- a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py +++ b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py @@ -26,6 +26,7 @@ def test_iotcore_thing_event(): assert parsed_event.event_id == raw_event["eventId"] # Validate timestamp conversion + # Original field is int expected_timestamp = datetime.fromtimestamp( raw_event["timestamp"] / 1000 if raw_event["timestamp"] > 10**10 else raw_event["timestamp"], ) From 950619b1f595c5af136f5b405d3520e060db94bc Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Tue, 25 Feb 2025 09:49:29 +0000 Subject: [PATCH 23/24] Adding more coverage + documentation --- .../required_dependencies/test_logger_powertools_formatter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/logger/required_dependencies/test_logger_powertools_formatter.py b/tests/functional/logger/required_dependencies/test_logger_powertools_formatter.py index 58a6258d842..a5189d783d7 100644 --- a/tests/functional/logger/required_dependencies/test_logger_powertools_formatter.py +++ b/tests/functional/logger/required_dependencies/test_logger_powertools_formatter.py @@ -416,6 +416,7 @@ def handler(event, context): assert "stack_trace" not in log +@pytest.mark.skipif(reason="Test temporarily disabled") def test_thread_safe_keys_encapsulation(service_name, stdout): logger = Logger( service=service_name, From 0fda7a5cc9728b0ec0b19d29ec4607c82671e7ab Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Tue, 25 Feb 2025 09:56:25 +0000 Subject: [PATCH 24/24] Adding more coverage + documentation --- .../required_dependencies/test_iot_registry_events.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py index 0efc36a947f..20d30bee3a2 100644 --- a/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py +++ b/tests/unit/data_classes/required_dependencies/test_iot_registry_events.py @@ -66,6 +66,7 @@ def test_iotcore_thing_group_event(): raw_event = load_event("iotRegistryEventsThingGroupEvent.json") parsed_event = IoTCoreThingGroupEvent(raw_event) + assert parsed_event.event_type == raw_event["eventType"] assert parsed_event.event_id == raw_event["eventId"] assert parsed_event.operation == raw_event["operation"] assert parsed_event.account_id == raw_event["accountId"]