Skip to content

Commit

Permalink
Add event type for cognito CustomMessage
Browse files Browse the repository at this point in the history
These events are used when running a lambda for customizing the SMS / Email
sent out during user signup, password reset, etc.
  • Loading branch information
jtetrault committed May 14, 2022
1 parent 5c48fdf commit 8d82c1a
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/aws_lambda_typing/events/__init__.py
Expand Up @@ -26,6 +26,7 @@
from .cloud_watch_logs import CloudWatchLogsEvent as CloudWatchLogsEvent
from .code_commit import CodeCommitMessageEvent as CodeCommitMessageEvent
from .code_pipeline import CodePipelineEvent as CodePipelineEvent
from .cognito_custom_message import CognitoCustomMessage as CognitoCustomMessage
from .config import ConfigEvent as ConfigEvent
from .dynamodb_stream import DynamoDBStreamEvent as DynamoDBStreamEvent
from .event_bridge import EventBridgeEvent as EventBridgeEvent
Expand Down
88 changes: 88 additions & 0 deletions src/aws_lambda_typing/events/cognito_custom_message.py
@@ -0,0 +1,88 @@
#!/usr/bin/env python

import sys
from typing import Literal

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

from typing_extensions import TypedDict


class CognitoCustomMessageCallerContext(TypedDict):
"""
CognitoCustomMessageCallerContext
Attributes:
----------:
awsSdk: str
clientId: str
"""

awsSdk: str
clientId: str


class CognitoCustomMessageRequestUserAttributes(TypedDict):
"""
CognitoCustomMessageRequestUserAttributes
Attributes:
----------:
phone_number_verified: bool
email_verified: bool
"""

phone_number_verified: bool
email_verified: bool


class CognitoCustomMessageRequest(TypedDict):
"""
CognitoCustomMessageRequest
Attributes:
----------:
userAttributes: CognitoCustomMessageRequestUserAttributes
"""


class CognitoCustomMessageResponse(TypedDict):
"""
CognitoCustomMessageResponse
Attributes:
----------:
userAttributes: CognitoCustomMessageRequestUserAttributes
"""

smsMessage: str
emailMessage: str
emailSubject: str


class CognitoCustomMessage(TypedDict):
"""
CognitoCustomMessage
https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-message.html
Attributes:
----------
triggerSource: str
"""

version: int
triggerSource: Literal[
"CustomMessage_SignUp",
"CustomMessage_ResendCode",
"CustomMessage_ForgotPassword",
"CustomMessage_VerifyUserAttribute",
]
region: str
userPoolId: str
userName: str
callerContext: CognitoCustomMessageCallerContext
request: CognitoCustomMessageRequest
response: CognitoCustomMessageResponse
27 changes: 27 additions & 0 deletions tests/events/test_cognito_custom_message.py
@@ -0,0 +1,27 @@
from aws_lambda_typing.events import CognitoCustomMessage


def test_cognito_custom_message_event() -> None:
event: CognitoCustomMessage = {
"version": 1,
"triggerSource": "CustomMessage_SignUp",
"region": "us-west-2",
"userPoolId": "poolid",
"userName": "userName",
"callerContext": {
"awsSdk": "1",
"clientId": "jkSDFasdfnsq",
},
"request": {
"userAttributes": {
"phone_number_verified": False,
"email_verified": True,
},
"codeParameter": "####",
},
"response": {
"smsMessage": "<custom message to be sent in the message with code parameter>",
"emailMessage": "<custom message to be sent in the message with code parameter>",
"emailSubject": "<custom email subject>",
},
}

0 comments on commit 8d82c1a

Please sign in to comment.