Refactoring: Adding typing for event message structure (#7234)

This commit is contained in:
Akira Noda 2024-01-23 23:39:22 +09:00 committed by Bert Blommers
parent 38ee3fa662
commit 38f6359dce
2 changed files with 28 additions and 4 deletions

View File

@ -1,16 +1,18 @@
import json
from typing import Any, Dict
from typing import Any
_EVENT_S3_OBJECT_CREATED: Dict[str, Any] = {
from .utils import EventMessageType
_EVENT_S3_OBJECT_CREATED: EventMessageType = {
"version": "0",
"id": "17793124-05d4-b198-2fde-7ededc63b103",
"detail-type": "Object Created",
"source": "aws.s3",
"account": "123456789012",
"time": "2021-11-12T00:00:00Z",
"region": None,
"region": "us-west-2",
"resources": [],
"detail": None,
"detail": {},
}

View File

@ -1,3 +1,25 @@
from typing import TYPE_CHECKING, List, TypedDict
if TYPE_CHECKING:
from typing_extentions import Any, Dict, Required, Union
# NOTE: Typing is based on the following document https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html
EventMessageType = TypedDict(
"EventMessageType",
{
"version": str,
"id": str,
"detail-type": "Required[Union[str, List[str]]]",
"source": "Required[Union[str, List[str]]]",
"account": str,
"time": str,
"region": str,
"resources": List[str],
"detail": "Required[Dict[str, Any]]",
},
)
PAGINATION_MODEL = {
"list_rules": {
"input_token": "next_token",