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
from aws_lambda_powertools.utilities.typing import LambdaContext | |
from typing import Any, Dict | |
def my_handler(event: Dict[str, Optional[Any]], context: LambdaContext) -> Dict[str, None]: | |
my_name: str = event['Records'][1]['name'] | |
# process input and produce output |
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
event = { | |
'title': 'rockz!', | |
'genre': 'Rock', | |
'release_date': str(date(2010, 10, 17)), | |
'artist': { | |
'name': 'Bon Jovi', | |
'age': 50, | |
} | |
} |
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
from pydantic import BaseModel, ValidationError, validator | |
from datetime import date | |
from typing import Optional | |
from typing_extensions import Literal | |
class Artist(BaseModel): | |
name: str | |
age: int | |
record_company: Optional[str] = 'independent' |
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
def handle_album(event: Dict[str, Optional[Any]], context: LambdaContext) -> None: | |
try: | |
parsed_event = Album(**event) | |
print(f'got title {parsed_event.title}') | |
print(f'got artist name {parsed_event.artist.name}') | |
except ValidationError as exc: | |
print(f'validation error, error={exc}') | |
return { | |
"statusCode": HTTPStatus.BAD_REQUEST, | |
"body": json.dumps({'error': 'invalid input'}), |
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
from botocore.exception import ClientError | |
from pydantic import ValidationError | |
from http import HTTPStatus | |
import boto3 | |
client = boto3.client('events') | |
try: | |
response = client.put_events(Entries=events) | |
parsed_response = EventBridgePutResponse(**response) |
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
class PutResponseMeta(BaseModel): | |
RequestId: str | |
HTTPStatusCode: HTTPStatus | |
HTTPHeaders: Dict[str, str] = {} | |
RetryAttempts: int | |
class EventBridgePutResponse(BaseModel): | |
FailedEntryCount: int | |
Entries: List[Dict[Literal['EventId'], str]] | |
ResponseMetadata: PutResponseMeta |
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
class PutResponseMeta(BaseModel): | |
HTTPStatusCode: HTTPStatus | |
class EventBridgePutResponse(BaseModel): | |
ResponseMetadata: PutResponseMeta |
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
from datetime import datetime | |
from typing import Any, Dict, List | |
from pydantic import BaseModel | |
class UserModel(BaseModel): | |
username: str | |
password1: str | |
password2: str | |
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
event = { | |
"version": "0", | |
"id": "6a7e8feb-b491-4cf7-a9f1-bf3703467718", | |
"detail-type": "CustomerSignedUp", | |
"source": "CustomerService", | |
"account": "111122223333", | |
"time": "2020-10-22T18:43:48Z", | |
"region": "us-west-1", | |
"resources": ["some_additional_"], | |
"detail": { |
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
from datetime import datetime | |
from typing import Any, Dict, List | |
from pydantic import BaseModel | |
from aws_lambda_powertools.utilities.parser import event_parser, parse, BaseModel, envelopes | |
from aws_lambda_powertools.utilities.typing import LambdaContext | |
class UserModel(BaseModel): | |
username: str |
OlderNewer