Skip to content

Commit 6cc7983

Browse files
feat(parser): Add IoT registry events models (#5892)
* Add IoT crud event * Fix typo * work * Added all registry events * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * Update aws_lambda_powertools/utilities/parser/models/iot_registry_events.py Co-authored-by: Leandro Damascena <[email protected]> Signed-off-by: Bas <[email protected]> * work * add tests * rename tests * rename test * wokr * Add documentation * Remove stars * Moving JSON events to events folder * Moving JSON events to events folder --------- Signed-off-by: Bas <[email protected]> Co-authored-by: Leandro Damascena <[email protected]>
1 parent af5e6be commit 6cc7983

11 files changed

+386
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
from datetime import datetime
2+
from typing import Any, Dict, List, Literal, Optional
3+
4+
from pydantic import BaseModel, Field
5+
6+
EVENT_CRUD_OPERATION = Literal["CREATED", "UPDATED", "DELETED"]
7+
EVENT_ADD_REMOVE_OPERATION = Literal["ADDED", "REMOVED"]
8+
9+
10+
class IoTCoreRegistryEventsBase(BaseModel):
11+
event_id: str = Field(..., alias="eventId")
12+
timestamp: datetime
13+
14+
15+
class IoTCoreThingEvent(IoTCoreRegistryEventsBase):
16+
"""
17+
Thing Created/Updated/Deleted
18+
19+
The registry publishes event messages when things are created, updated, or deleted.
20+
"""
21+
22+
event_type: Literal["THING_EVENT"] = Field(..., alias="eventType")
23+
operation: EVENT_CRUD_OPERATION
24+
thing_id: str = Field(..., alias="thingId")
25+
account_id: str = Field(..., alias="accountId")
26+
thing_name: str = Field(..., alias="thingName")
27+
version_number: int = Field(..., alias="versionNumber")
28+
thing_type_name: Optional[str] = Field(None, alias="thingTypeName")
29+
attributes: Dict[str, Any]
30+
31+
32+
class IoTCoreThingTypeEvent(IoTCoreRegistryEventsBase):
33+
"""
34+
Thing Type Created/Updated/Deprecated/Undeprecated/Deleted
35+
The registry publishes event messages when thing types are created, updated, deprecated, undeprecated, or deleted.
36+
37+
Format:
38+
$aws/events/thingType/thingTypeName/created
39+
$aws/events/thingType/thingTypeName/updated
40+
$aws/events/thingType/thingTypeName/deleted
41+
"""
42+
43+
event_type: Literal["THING_TYPE_EVENT"] = Field(..., alias="eventType")
44+
operation: EVENT_CRUD_OPERATION
45+
account_id: str = Field(..., alias="accountId")
46+
thing_type_id: str = Field(..., alias="thingTypeId")
47+
thing_type_name: str = Field(..., alias="thingTypeName")
48+
is_deprecated: bool = Field(..., alias="isDeprecated")
49+
deprecation_date: Optional[datetime] = Field(None, alias="deprecationDate")
50+
searchable_attributes: List[str] = Field(..., alias="searchableAttributes")
51+
propagating_attributes: List[Dict[str, str]] = Field(..., alias="propagatingAttributes")
52+
description: str
53+
54+
55+
class IoTCoreThingTypeAssociationEvent(IoTCoreRegistryEventsBase):
56+
"""
57+
The registry publishes event messages when a thing type is associated or disassociated with a thing.
58+
59+
Format:
60+
$aws/events/thingTypeAssociation/thing/thingName/thingType/typeName/added
61+
$aws/events/thingTypeAssociation/thing/thingName/thingType/typeName/removed
62+
"""
63+
64+
event_type: Literal["THING_TYPE_ASSOCIATION_EVENT"] = Field(..., alias="eventType")
65+
operation: EVENT_ADD_REMOVE_OPERATION
66+
thing_id: str = Field(..., alias="thingId")
67+
thing_name: str = Field(..., alias="thingName")
68+
thing_type_name: str = Field(..., alias="thingTypeName")
69+
70+
71+
class IoTCoreThingGroupEvent(IoTCoreRegistryEventsBase):
72+
"""
73+
The registry publishes the following event messages when a thing group is created, updated, or deleted.
74+
75+
Format:
76+
$aws/events/thingGroup/groupName/created
77+
$aws/events/thingGroup/groupName/updated
78+
$aws/events/thingGroup/groupName/deleted
79+
"""
80+
81+
event_type: Literal["THING_GROUP_EVENT"] = Field(..., alias="eventType")
82+
operation: EVENT_CRUD_OPERATION
83+
account_id: str = Field(..., alias="accountId")
84+
thing_group_id: str = Field(..., alias="thingGroupId")
85+
thing_group_name: str = Field(..., alias="thingGroupName")
86+
version_number: int = Field(..., alias="versionNumber")
87+
parent_group_name: Optional[str] = Field(None, alias="parentGroupName")
88+
parent_group_id: Optional[str] = Field(None, alias="parentGroupId")
89+
description: str
90+
root_to_parent_thing_groups: List[Dict[str, str]] = Field(..., alias="rootToParentThingGroups")
91+
attributes: Dict[str, Any]
92+
dynamic_group_mapping_id: Optional[str] = Field(None, alias="dynamicGroupMappingId")
93+
94+
95+
class IoTCoreAddOrRemoveFromThingGroupEvent(IoTCoreRegistryEventsBase):
96+
"""
97+
The registry publishes event messages when a thing is added to or removed from a thing group.
98+
99+
Format:
100+
$aws/events/thingGroupMembership/thingGroup/thingGroupName/thing/thingName/added
101+
$aws/events/thingGroupMembership/thingGroup/thingGroupName/thing/thingName/removed
102+
"""
103+
104+
event_type: Literal["THING_GROUP_MEMBERSHIP_EVENT"] = Field(..., alias="eventType")
105+
operation: EVENT_ADD_REMOVE_OPERATION
106+
account_id: str = Field(..., alias="accountId")
107+
group_arn: str = Field(..., alias="groupArn")
108+
group_id: str = Field(..., alias="groupId")
109+
thing_arn: str = Field(..., alias="thingArn")
110+
thing_id: str = Field(..., alias="thingId")
111+
membership_id: str = Field(..., alias="membershipId")
112+
113+
114+
class IoTCoreAddOrDeleteFromThingGroupEvent(IoTCoreRegistryEventsBase):
115+
"""
116+
The registry publishes event messages when a thing group is added to or removed from another thing group.
117+
118+
Format:
119+
$aws/events/thingGroupHierarchy/thingGroup/parentThingGroupName/childThingGroup/childThingGroupName/added
120+
$aws/events/thingGroupHierarchy/thingGroup/parentThingGroupName/childThingGroup/childThingGroupName/removed
121+
"""
122+
123+
event_type: Literal["THING_GROUP_HIERARCHY_EVENT"] = Field(..., alias="eventType")
124+
operation: EVENT_ADD_REMOVE_OPERATION
125+
account_id: str = Field(..., alias="accountId")
126+
thing_group_id: str = Field(..., alias="thingGroupId")
127+
thing_group_name: str = Field(..., alias="thingGroupName")
128+
child_group_id: str = Field(..., alias="childGroupId")
129+
child_group_name: str = Field(..., alias="childGroupName")

docs/utilities/parser.md

+41-35
Original file line numberDiff line numberDiff line change
@@ -100,41 +100,47 @@ You can use pre-built models to work events from AWS services, so you don’t ne
100100

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

103-
| Model name | Description |
104-
| ------------------------------------------- | ------------------------------------------------------------------------------------- |
105-
| **AlbModel** | Lambda Event Source payload for Amazon Application Load Balancer |
106-
| **APIGatewayProxyEventModel** | Lambda Event Source payload for Amazon API Gateway |
107-
| **ApiGatewayAuthorizerToken** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Token |
108-
| **ApiGatewayAuthorizerRequest** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Request |
109-
| **APIGatewayProxyEventV2Model** | Lambda Event Source payload for Amazon API Gateway v2 payload |
110-
| **ApiGatewayAuthorizerRequestV2** | Lambda Event Source payload for Amazon API Gateway v2 Lambda Authorizer |
111-
| **APIGatewayWebSocketMessageEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API message body |
112-
| **APIGatewayWebSocketConnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $connect message |
113-
| **APIGatewayWebSocketDisconnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $disconnect message |
114-
| **BedrockAgentEventModel** | Lambda Event Source payload for Bedrock Agents |
115-
| **CloudFormationCustomResourceCreateModel** | Lambda Event Source payload for AWS CloudFormation `CREATE` operation |
116-
| **CloudFormationCustomResourceUpdateModel** | Lambda Event Source payload for AWS CloudFormation `UPDATE` operation |
117-
| **CloudFormationCustomResourceDeleteModel** | Lambda Event Source payload for AWS CloudFormation `DELETE` operation |
118-
| **CloudwatchLogsModel** | Lambda Event Source payload for Amazon CloudWatch Logs |
119-
| **DynamoDBStreamModel** | Lambda Event Source payload for Amazon DynamoDB Streams |
120-
| **EventBridgeModel** | Lambda Event Source payload for Amazon EventBridge |
121-
| **KafkaMskEventModel** | Lambda Event Source payload for AWS MSK payload |
122-
| **KafkaSelfManagedEventModel** | Lambda Event Source payload for self managed Kafka payload |
123-
| **KinesisDataStreamModel** | Lambda Event Source payload for Amazon Kinesis Data Streams |
124-
| **KinesisFirehoseModel** | Lambda Event Source payload for Amazon Kinesis Firehose |
125-
| **KinesisFirehoseSqsModel** | Lambda Event Source payload for SQS messages wrapped in Kinesis Firehose records |
126-
| **LambdaFunctionUrlModel** | Lambda Event Source payload for Lambda Function URL payload |
127-
| **S3BatchOperationModel** | Lambda Event Source payload for Amazon S3 Batch Operation |
128-
| **S3EventNotificationEventBridgeModel** | Lambda Event Source payload for Amazon S3 Event Notification to EventBridge. |
129-
| **S3Model** | Lambda Event Source payload for Amazon S3 |
130-
| **S3ObjectLambdaEvent** | Lambda Event Source payload for Amazon S3 Object Lambda |
131-
| **S3SqsEventNotificationModel** | Lambda Event Source payload for S3 event notifications wrapped in SQS event (S3->SQS) |
132-
| **SesModel** | Lambda Event Source payload for Amazon Simple Email Service |
133-
| **SnsModel** | Lambda Event Source payload for Amazon Simple Notification Service |
134-
| **SqsModel** | Lambda Event Source payload for Amazon SQS |
135-
| **TransferFamilyAuthorizer** | Lambda Event Source payload for AWS Transfer Family Lambda authorizer |
136-
| **VpcLatticeModel** | Lambda Event Source payload for Amazon VPC Lattice |
137-
| **VpcLatticeV2Model** | Lambda Event Source payload for Amazon VPC Lattice v2 payload |
103+
| Model name | Description |
104+
| ------------------------------------------- | --------------------------------------------------------------------------------------------- |
105+
| **AlbModel** | Lambda Event Source payload for Amazon Application Load Balancer |
106+
| **APIGatewayProxyEventModel** | Lambda Event Source payload for Amazon API Gateway |
107+
| **ApiGatewayAuthorizerToken** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Token |
108+
| **ApiGatewayAuthorizerRequest** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Request |
109+
| **APIGatewayProxyEventV2Model** | Lambda Event Source payload for Amazon API Gateway v2 payload |
110+
| **ApiGatewayAuthorizerRequestV2** | Lambda Event Source payload for Amazon API Gateway v2 Lambda Authorizer |
111+
| **APIGatewayWebSocketMessageEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API message body |
112+
| **APIGatewayWebSocketConnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $connect message |
113+
| **APIGatewayWebSocketDisconnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $disconnect message |
114+
| **BedrockAgentEventModel** | Lambda Event Source payload for Bedrock Agents |
115+
| **CloudFormationCustomResourceCreateModel** | Lambda Event Source payload for AWS CloudFormation `CREATE` operation |
116+
| **CloudFormationCustomResourceUpdateModel** | Lambda Event Source payload for AWS CloudFormation `UPDATE` operation |
117+
| **CloudFormationCustomResourceDeleteModel** | Lambda Event Source payload for AWS CloudFormation `DELETE` operation |
118+
| **CloudwatchLogsModel** | Lambda Event Source payload for Amazon CloudWatch Logs |
119+
| **DynamoDBStreamModel** | Lambda Event Source payload for Amazon DynamoDB Streams |
120+
| **EventBridgeModel** | Lambda Event Source payload for Amazon EventBridge |
121+
| **IoTCoreThingEvent** | Lambda Event Source payload for IoT Core Thing created, updated, or deleted. |
122+
| **IoTCoreThingTypeEvent** | Lambda Event Source payload for IoT Core Thing Type events. |
123+
| **IoTCoreThingTypeAssociationEvent** | Lambda Event Source payload for IoT Core Thing Type associated or disassociated with a Thing. |
124+
| **IoTCoreThingGroupEvent** | Lambda Event Source payload for IoT Core Thing Group created, updated, or deleted. |
125+
| **IoTCoreAddOrRemoveFromThingGroupEvent** | Lambda Event Source payload for IoT Core Thing added to or removed from a Thing Group. |
126+
| **IoTCoreAddOrDeleteFromThingGroupEvent** | Lambda Event Source payload for IoT Core Thing Group added to or deleted from a Thing Group. |
127+
| **KafkaMskEventModel** | Lambda Event Source payload for AWS MSK payload |
128+
| **KafkaSelfManagedEventModel** | Lambda Event Source payload for self managed Kafka payload |
129+
| **KinesisDataStreamModel** | Lambda Event Source payload for Amazon Kinesis Data Streams |
130+
| **KinesisFirehoseModel** | Lambda Event Source payload for Amazon Kinesis Firehose |
131+
| **KinesisFirehoseSqsModel** | Lambda Event Source payload for SQS messages wrapped in Kinesis Firehose records |
132+
| **LambdaFunctionUrlModel** | Lambda Event Source payload for Lambda Function URL payload |
133+
| **S3BatchOperationModel** | Lambda Event Source payload for Amazon S3 Batch Operation |
134+
| **S3EventNotificationEventBridgeModel** | Lambda Event Source payload for Amazon S3 Event Notification to EventBridge. |
135+
| **S3Model** | Lambda Event Source payload for Amazon S3 |
136+
| **S3ObjectLambdaEvent** | Lambda Event Source payload for Amazon S3 Object Lambda |
137+
| **S3SqsEventNotificationModel** | Lambda Event Source payload for S3 event notifications wrapped in SQS event (S3->SQS) |
138+
| **SesModel** | Lambda Event Source payload for Amazon Simple Email Service |
139+
| **SnsModel** | Lambda Event Source payload for Amazon Simple Notification Service |
140+
| **SqsModel** | Lambda Event Source payload for Amazon SQS |
141+
| **TransferFamilyAuthorizer** | Lambda Event Source payload for AWS Transfer Family Lambda authorizer |
142+
| **VpcLatticeModel** | Lambda Event Source payload for Amazon VPC Lattice |
143+
| **VpcLatticeV2Model** | Lambda Event Source payload for Amazon VPC Lattice v2 payload |
138144

139145
#### Extending built-in models
140146

tests/events/codePipelineEventWithEncryptionKey.json

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

0 commit comments

Comments
 (0)