Skip to content

Commit

Permalink
Merge branch 'master' into cognito_custom_message
Browse files Browse the repository at this point in the history
  • Loading branch information
MousaZeidBaker committed May 19, 2022
2 parents ce9f48f + c4b8f4b commit d769dfc
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 86 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -79,6 +79,10 @@ def handler(event: events.SQSEvent, context: context_.Context) -> None:
- SNSEvent
- SQSEvent

### Requests
- SNSPublish
- SNSPublishBatch

### Responses
- ALBResponse
- APIGatewayAuthorizerResponse
Expand Down
167 changes: 84 additions & 83 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Expand Up @@ -30,7 +30,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.6"
typing-extensions = { version = "^4.0.1", python = "<3.8" }
typing-extensions = { version = "^4.1.1", python = "<3.8" }

[tool.poetry.dev-dependencies]
mypy = "^0.910"
Expand All @@ -39,9 +39,9 @@ black = [
{version = "^22.3.0", python = ">3.6.2"},
]
flake8 = "^4.0.1"
flake8-black = "^0.2.4"
flake8-black = "^0.2.5"
flake8-isort = "^4.1.1"
flake8-eradicate = "^1.2.0"
flake8-eradicate = "^1.2.1"
isort = { version = "^5.10.1", python = "^3.6.1" }
pre-commit = { version = "^2.17.0", python = "^3.6.1" }

Expand Down
2 changes: 2 additions & 0 deletions src/aws_lambda_typing/requests/__init__.py
@@ -0,0 +1,2 @@
from .sns import SNSPublish as SNSPublish
from .sns import SNSPublishBatch as SNSPublishBatch
124 changes: 124 additions & 0 deletions src/aws_lambda_typing/requests/sns.py
@@ -0,0 +1,124 @@
#!/usr/bin/env python

import sys

if sys.version_info >= (3, 8):
from typing import Any, Dict, List, Literal, Optional, TypedDict, Union
else:
from typing import Any, Dict, List, Optional, Union

from typing_extensions import Literal, TypedDict


class MessageAttributesString(TypedDict):
"""
MessageAttributesString
Attributes:
----------
DataType: str
StringValue: str
BinaryValue: Any
"""

DataType: str
StringValue: Optional[str]
BinaryValue: Optional[Any]


class MessageAttributes(TypedDict):
"""
MessageAttributes
Attributes:
----------
string: py:class:`MessageAttributesString`
"""

string: MessageAttributesString


class PublishBatchRequestEntry(TypedDict, total=False):
"""
PublishBatchRequestEntry
https://docs.aws.amazon.com/sns/latest/api/API_PublishBatchRequestEntry.html
Attributes:
----------
Id: str
Message: str
MessageAttributes: Optional[:py:class:`MessageAttributes`]
MessageDeduplicationId: Optional[str]
MessageGroupId: Optional[str]
MessageStructure: Optional[str]
Subject: Optional[str]
"""

Id: str
Message: str
MessageAttributes: Optional[MessageAttributes]
MessageDeduplicationId: Optional[str]
MessageGroupId: Optional[str]
MessageStructure: Optional[str]
Subject: Optional[str]


class SNSPublish(TypedDict, total=False):
"""
SNSPublish
https://docs.aws.amazon.com/sns/latest/api/API_Publish.html
Attributes:
----------
Message: Union[str, Dict[str, str]]
MessageAttributes: Optional[:py:class:`MessageAttributes`]
MessageDeduplicationId: Optional[str]
MessageGroupId: Optional[str]
MessageStructure: Optional[Literal["json"]]
PhoneNumber: Optional[str]
Subject: Optional[str]
TargetArn: Optional[str]
TopicArn: Optional[str]
"""

Message: Union[str, Dict[str, str]]
MessageAttributes: Optional[MessageAttributes]
MessageDeduplicationId: Optional[str]
MessageGroupId: Optional[str]
MessageStructure: Optional[Literal["json"]]
PhoneNumber: Optional[str]
Subject: Optional[str]
TargetArn: Optional[str]
TopicArn: Optional[str]


class SNSPublishBatch(TypedDict, total=False):
"""
SNSPublishBatch
https://docs.aws.amazon.com/sns/latest/api/API_PublishBatch.html
Attributes:
----------
TopicArn: str
PublishBatchRequestEntries: List[:py:class:`PublishBatchRequestEntry`]
"""

TopicArn: str
PublishBatchRequestEntries: List[PublishBatchRequestEntry]
Empty file added tests/requests/__init__.py
Empty file.
44 changes: 44 additions & 0 deletions tests/requests/test_sns.py
@@ -0,0 +1,44 @@
from aws_lambda_typing.requests import SNSPublish, SNSPublishBatch


def test_sns_publish() -> None:
request: SNSPublish = {
"Message": "Hello World",
"MessageAttributes": {
"string": {
"DataType": "string",
"StringValue": "string",
"BinaryValue": b"bytes",
}
},
"MessageDeduplicationId": "string",
"MessageGroupId": "string",
"MessageStructure": "json",
"PhoneNumber": "string",
"Subject": "string",
"TargetArn": "string",
"TopicArn": "string",
}


def test_sns_publish_batch() -> None:
request: SNSPublishBatch = {
"TopicArn": "string",
"PublishBatchRequestEntries": [
{
"Id": "string",
"Message": "Hello World",
"MessageAttributes": {
"string": {
"DataType": "string",
"StringValue": "string",
"BinaryValue": b"bytes",
}
},
"MessageDeduplicationId": "string",
"MessageGroupId": "string",
"MessageStructure": "json",
"Subject": "string",
}
],
}

0 comments on commit d769dfc

Please sign in to comment.