Skip to content

Instantly share code, notes, and snippets.

@gbvanrenswoude
Created September 17, 2021 14:51
Show Gist options
  • Save gbvanrenswoude/7c4c437c04566dac1dbef5d2c1941339 to your computer and use it in GitHub Desktop.
Save gbvanrenswoude/7c4c437c04566dac1dbef5d2c1941339 to your computer and use it in GitHub Desktop.
custom-event-bridge-code-binding
# Lets take a simple event
# and event.json is the jsonschema of it
# {
# "administration": "YOURBACKOFFICECODE",
# "personNumber": 1337
# }
import json
from logging import getLogger, INFO
from schema.pogu import Event, Marshaller
from aws_lambda_powertools.utilities.validation import validator
logger = getLogger()
logger.setLevel(INFO)
with open('schemas/event.json', 'r') as file:
event_schema = json.loads(file.read())
@validator(inbound_schema=event_schema)
def handler(event: Event, context):
# Deserialize event into strongly typed object (but what is the added value in PY tov notating event as Event in the handler method)
customEvent: Event = Marshaller.unmarshall(event, Event)
adminstratie: str = customEvent.administration
personNumber: int = customEvent.personNumber
logger.info(adminstratie + str(personNumber))
# rest of the function logic goes brrrrr
# for example make some update to event payload
customEvent.administration = "POG U updated event of " + customEvent.administration
# Return the event again
return Marshaller.marshall(customEvent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment