Last active
July 31, 2021 12:29
-
-
Save liavyona/d84dfaae7508155d846723a19b08e7cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Built-ins | |
from os import getenv | |
from json import dumps | |
from typing import Any, Dict | |
from http import HTTPStatus | |
# Third party | |
from aws_lambda_powertools.utilities.typing import LambdaContext | |
from aws_lambda_powertools.utilities.parser import event_parser, BaseModel | |
import boto3 | |
class UserInsertionEvent(BaseModel): | |
firstname: str | |
lastname: str | |
created_at: str | |
@event_parser(model=UserInsertionEvent) | |
def handler(event: UserInsertionEvent, context: LambdaContext) -> Dict[str, Any]: | |
client = boto3.client("sns") | |
response = client.publish( | |
TopicArn=getenv("NOTIFICATION_TOPIC_ARN"), | |
Message=f"A new user was added at {event.created_at}: {event.firstname} {event.lastname}" | |
) | |
return { | |
"lambda_request_id": context.aws_request_id, | |
"lambda_arn": context.invoked_function_arn, | |
"status_code": HTTPStatus.OK.value, | |
"event": event.json(), | |
"response": response | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment