Skip to content

feat(parser): Add IoT registry events models #5892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
44f0855
Add IoT crud event
basvandriel Jan 21, 2025
48d6da8
Fix typo
basvandriel Jan 21, 2025
8ecda5d
Merge branch 'develop' into feature/iot-core-crud-event-types
basvandriel Jan 22, 2025
dce4fa7
work
basvandriel Jan 22, 2025
39223c7
Merge branch 'develop' into feature/iot-core-crud-event-types
basvandriel Jan 22, 2025
5418544
Merge branch 'develop' into feature/iot-core-crud-event-types
basvandriel Jan 23, 2025
10415a8
Merge branch 'develop' into feature/iot-core-crud-event-types
basvandriel Jan 30, 2025
bddff92
Merge branch 'develop' into feature/iot-core-crud-event-types
basvandriel Jan 31, 2025
fffd8f4
Merge branch 'develop' into feature/iot-core-crud-event-types
leandrodamascena Feb 8, 2025
984aef5
Added all registry events
basvandriel Feb 13, 2025
798272e
Merge branch 'develop' into feature/iot-core-crud-event-types
basvandriel Feb 13, 2025
d528624
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
5ab83ff
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
28a0d83
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
49536f9
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
a252254
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
06456eb
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
9753bbf
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
c5a2e6f
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
86f1d91
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
8788bff
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
74d9dbf
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
f03655d
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
b66e5d8
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
074d64f
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
9b323c9
Update aws_lambda_powertools/utilities/parser/models/iot_registry_eve…
basvandriel Feb 13, 2025
a42daaa
Merge branch 'develop' into feature/iot-core-crud-event-types
basvandriel Feb 13, 2025
c7602ef
work
basvandriel Feb 13, 2025
674f973
add tests
basvandriel Feb 13, 2025
bf5f3df
rename tests
basvandriel Feb 13, 2025
bfd8d93
rename test
basvandriel Feb 13, 2025
9e8aae2
wokr
basvandriel Feb 14, 2025
501ce1c
Add documentation
basvandriel Feb 14, 2025
0fd6f6e
Remove stars
basvandriel Feb 14, 2025
30a73d5
Merge branch 'develop' into feature/iot-core-crud-event-types
leandrodamascena Feb 14, 2025
9268902
Moving JSON events to events folder
leandrodamascena Feb 14, 2025
7068d1a
Moving JSON events to events folder
leandrodamascena Feb 14, 2025
5719499
Merge branch 'develop' into feature/iot-core-crud-event-types
leandrodamascena Feb 14, 2025
778cac6
Merge branch 'develop' into feature/iot-core-crud-event-types
leandrodamascena Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions aws_lambda_powertools/utilities/parser/models/iot_registry_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
from datetime import datetime
from typing import Any, Dict, List, Literal, Optional

from pydantic import BaseModel, Field

EVENT_CRUD_OPERATION = Literal["CREATED", "UPDATED", "DELETED"]
EVENT_ADD_REMOVE_OPERATION = Literal["ADDED", "REMOVED"]


class IoTCoreRegistryEventsBase(BaseModel):
event_id: str = Field(..., alias="eventId")
timestamp: datetime


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]


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
"""

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(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
"""

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(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
"""

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(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
"""

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(IoTCoreRegistryEventsBase):
"""
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")
76 changes: 41 additions & 35 deletions docs/utilities/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,41 +100,47 @@ You can use pre-built models to work events from AWS services, so you don’t ne

The example above uses `SqsModel`. Other built-in models can be found below.

| Model name | Description |
| ------------------------------------------- | ------------------------------------------------------------------------------------- |
| **AlbModel** | Lambda Event Source payload for Amazon Application Load Balancer |
| **APIGatewayProxyEventModel** | Lambda Event Source payload for Amazon API Gateway |
| **ApiGatewayAuthorizerToken** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Token |
| **ApiGatewayAuthorizerRequest** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Request |
| **APIGatewayProxyEventV2Model** | Lambda Event Source payload for Amazon API Gateway v2 payload |
| **ApiGatewayAuthorizerRequestV2** | Lambda Event Source payload for Amazon API Gateway v2 Lambda Authorizer |
| **APIGatewayWebSocketMessageEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API message body |
| **APIGatewayWebSocketConnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $connect message |
| **APIGatewayWebSocketDisconnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $disconnect message |
| **BedrockAgentEventModel** | Lambda Event Source payload for Bedrock Agents |
| **CloudFormationCustomResourceCreateModel** | Lambda Event Source payload for AWS CloudFormation `CREATE` operation |
| **CloudFormationCustomResourceUpdateModel** | Lambda Event Source payload for AWS CloudFormation `UPDATE` operation |
| **CloudFormationCustomResourceDeleteModel** | Lambda Event Source payload for AWS CloudFormation `DELETE` operation |
| **CloudwatchLogsModel** | Lambda Event Source payload for Amazon CloudWatch Logs |
| **DynamoDBStreamModel** | Lambda Event Source payload for Amazon DynamoDB Streams |
| **EventBridgeModel** | Lambda Event Source payload for Amazon EventBridge |
| **KafkaMskEventModel** | Lambda Event Source payload for AWS MSK payload |
| **KafkaSelfManagedEventModel** | Lambda Event Source payload for self managed Kafka payload |
| **KinesisDataStreamModel** | Lambda Event Source payload for Amazon Kinesis Data Streams |
| **KinesisFirehoseModel** | Lambda Event Source payload for Amazon Kinesis Firehose |
| **KinesisFirehoseSqsModel** | Lambda Event Source payload for SQS messages wrapped in Kinesis Firehose records |
| **LambdaFunctionUrlModel** | Lambda Event Source payload for Lambda Function URL payload |
| **S3BatchOperationModel** | Lambda Event Source payload for Amazon S3 Batch Operation |
| **S3EventNotificationEventBridgeModel** | Lambda Event Source payload for Amazon S3 Event Notification to EventBridge. |
| **S3Model** | Lambda Event Source payload for Amazon S3 |
| **S3ObjectLambdaEvent** | Lambda Event Source payload for Amazon S3 Object Lambda |
| **S3SqsEventNotificationModel** | Lambda Event Source payload for S3 event notifications wrapped in SQS event (S3->SQS) |
| **SesModel** | Lambda Event Source payload for Amazon Simple Email Service |
| **SnsModel** | Lambda Event Source payload for Amazon Simple Notification Service |
| **SqsModel** | Lambda Event Source payload for Amazon SQS |
| **TransferFamilyAuthorizer** | Lambda Event Source payload for AWS Transfer Family Lambda authorizer |
| **VpcLatticeModel** | Lambda Event Source payload for Amazon VPC Lattice |
| **VpcLatticeV2Model** | Lambda Event Source payload for Amazon VPC Lattice v2 payload |
| Model name | Description |
| ------------------------------------------- | --------------------------------------------------------------------------------------------- |
| **AlbModel** | Lambda Event Source payload for Amazon Application Load Balancer |
| **APIGatewayProxyEventModel** | Lambda Event Source payload for Amazon API Gateway |
| **ApiGatewayAuthorizerToken** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Token |
| **ApiGatewayAuthorizerRequest** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Request |
| **APIGatewayProxyEventV2Model** | Lambda Event Source payload for Amazon API Gateway v2 payload |
| **ApiGatewayAuthorizerRequestV2** | Lambda Event Source payload for Amazon API Gateway v2 Lambda Authorizer |
| **APIGatewayWebSocketMessageEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API message body |
| **APIGatewayWebSocketConnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $connect message |
| **APIGatewayWebSocketDisconnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $disconnect message |
| **BedrockAgentEventModel** | Lambda Event Source payload for Bedrock Agents |
| **CloudFormationCustomResourceCreateModel** | Lambda Event Source payload for AWS CloudFormation `CREATE` operation |
| **CloudFormationCustomResourceUpdateModel** | Lambda Event Source payload for AWS CloudFormation `UPDATE` operation |
| **CloudFormationCustomResourceDeleteModel** | Lambda Event Source payload for AWS CloudFormation `DELETE` operation |
| **CloudwatchLogsModel** | Lambda Event Source payload for Amazon CloudWatch Logs |
| **DynamoDBStreamModel** | Lambda Event Source payload for Amazon DynamoDB Streams |
| **EventBridgeModel** | Lambda Event Source payload for Amazon EventBridge |
| **IoTCoreThingEvent** | Lambda Event Source payload for IoT Core Thing created, updated, or deleted. |
| **IoTCoreThingTypeEvent** | Lambda Event Source payload for IoT Core Thing Type events. |
| **IoTCoreThingTypeAssociationEvent** | Lambda Event Source payload for IoT Core Thing Type associated or disassociated with a Thing. |
| **IoTCoreThingGroupEvent** | Lambda Event Source payload for IoT Core Thing Group created, updated, or deleted. |
| **IoTCoreAddOrRemoveFromThingGroupEvent** | Lambda Event Source payload for IoT Core Thing added to or removed from a Thing Group. |
| **IoTCoreAddOrDeleteFromThingGroupEvent** | Lambda Event Source payload for IoT Core Thing Group added to or deleted from a Thing Group. |
| **KafkaMskEventModel** | Lambda Event Source payload for AWS MSK payload |
| **KafkaSelfManagedEventModel** | Lambda Event Source payload for self managed Kafka payload |
| **KinesisDataStreamModel** | Lambda Event Source payload for Amazon Kinesis Data Streams |
| **KinesisFirehoseModel** | Lambda Event Source payload for Amazon Kinesis Firehose |
| **KinesisFirehoseSqsModel** | Lambda Event Source payload for SQS messages wrapped in Kinesis Firehose records |
| **LambdaFunctionUrlModel** | Lambda Event Source payload for Lambda Function URL payload |
| **S3BatchOperationModel** | Lambda Event Source payload for Amazon S3 Batch Operation |
| **S3EventNotificationEventBridgeModel** | Lambda Event Source payload for Amazon S3 Event Notification to EventBridge. |
| **S3Model** | Lambda Event Source payload for Amazon S3 |
| **S3ObjectLambdaEvent** | Lambda Event Source payload for Amazon S3 Object Lambda |
| **S3SqsEventNotificationModel** | Lambda Event Source payload for S3 event notifications wrapped in SQS event (S3->SQS) |
| **SesModel** | Lambda Event Source payload for Amazon Simple Email Service |
| **SnsModel** | Lambda Event Source payload for Amazon Simple Notification Service |
| **SqsModel** | Lambda Event Source payload for Amazon SQS |
| **TransferFamilyAuthorizer** | Lambda Event Source payload for AWS Transfer Family Lambda authorizer |
| **VpcLatticeModel** | Lambda Event Source payload for Amazon VPC Lattice |
| **VpcLatticeV2Model** | Lambda Event Source payload for Amazon VPC Lattice v2 payload |

#### Extending built-in models

Expand Down
2 changes: 1 addition & 1 deletion tests/events/codePipelineEventWithEncryptionKey.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"continuationToken": "A continuation token if continuing job",
"encryptionKey": {
"id": "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
"id": "validkmskey",
"type": "KMS"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"eventType": "THING_GROUP_HIERARCHY_EVENT",
"eventId": "264192c7-b573-46ef-ab7b-489fcd47da41",
"timestamp": 1234567890123,
"operation": "ADDED",
"accountId": "123456789012",
"thingGroupId": "8f82a106-6b1d-4331-8984-a84db5f6f8cb",
"thingGroupName": "MyRootThingGroup",
"childGroupId": "06838589-373f-4312-b1f2-53f2192291c4",
"childGroupName": "MyChildThingGroup"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"eventType": "THING_GROUP_MEMBERSHIP_EVENT",
"eventId": "d684bd5f-6f6e-48e1-950c-766ac7f02fd1",
"timestamp": 1234567890123,
"operation": "ADDED",
"accountId": "123456789012",
"groupArn": "arn:aws:iot:ap-northeast-2:123456789012:thinggroup/MyChildThingGroup",
"groupId": "06838589-373f-4312-b1f2-53f2192291c4",
"thingArn": "arn:aws:iot:ap-northeast-2:123456789012:thing/MyThing",
"thingId": "b604f69c-aa9a-4d4a-829e-c480e958a0b5",
"membershipId": "8505ebf8-4d32-4286-80e9-c23a4a16bbd8"
}
12 changes: 12 additions & 0 deletions tests/events/iotRegistryEventsThingEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"eventType": "THING_EVENT",
"eventId": "f5ae9b94-8b8e-4d8e-8c8f-b3266dd89853",
"timestamp": 1234567890123,
"operation": "CREATED",
"accountId": "123456789012",
"thingId": "b604f69c-aa9a-4d4a-829e-c480e958a0b5",
"thingName": "MyThing",
"versionNumber": 1,
"thingTypeName": null,
"attributes": {"attribute3": "value3", "attribute1": "value1", "attribute2": "value2"}
}
37 changes: 37 additions & 0 deletions tests/events/iotRegistryEventsThingGroupEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"eventType": "THING_GROUP_EVENT",
"eventId": "8b9ea8626aeaa1e42100f3f32b975899",
"timestamp": 1603995417409,
"operation": "UPDATED",
"accountId": "571EXAMPLE833",
"thingGroupId": "8757eec8-bb37-4cca-a6fa-403b003d139f",
"thingGroupName": "Tg_level5",
"versionNumber": 3,
"parentGroupName": "Tg_level4",
"parentGroupId": "5fce366a-7875-4c0e-870b-79d8d1dce119",
"description": "New description for Tg_level5",
"rootToParentThingGroups": [
{
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/TgTopLevel",
"groupId": "36aa0482-f80d-4e13-9bff-1c0a75c055f6"
},
{
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/Tg_level1",
"groupId": "bc1643e1-5a85-4eac-b45a-92509cbe2a77"
},
{
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/Tg_level2",
"groupId": "0476f3d2-9beb-48bb-ae2c-ea8bd6458158"
},
{
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/Tg_level3",
"groupId": "1d9d4ffe-a6b0-48d6-9de6-2e54d1eae78f"
},
{
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/Tg_level4",
"groupId": "5fce366a-7875-4c0e-870b-79d8d1dce119"
}
],
"attributes": {"attribute1": "value1", "attribute3": "value3", "attribute2": "value2"},
"dynamicGroupMappingId": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"eventId": "87f8e095-531c-47b3-aab5-5171364d138d",
"eventType": "THING_TYPE_ASSOCIATION_EVENT",
"operation": "ADDED",
"thingId": "b604f69c-aa9a-4d4a-829e-c480e958a0b5",
"thingName": "myThing",
"thingTypeName": "MyThingType",
"timestamp": 1234567890123
}
Loading
Loading