AWS Lex Python Event Autocomplete

AWS Lambda is amazing and WavyCloud’s language of choice is Python. One caveat is the lack of autocomplete on events you receive. So you end up navigating dictionaries and hopefully not have a misspelling of the keys. You also have to remember dictionary structure or keep looking up source event documentation.

We wanted a consistent way to navigate those event dictionaries with auto-complete support. Also, we want to easily construct responses and copy relevant information from input event with autocomplete as well.

We started by having a class that will stores these variables in an object as well as helper functions to create each response type. It was messy but it worked. Eventually we decided to create pylexo to solve that problem.

Pylexo wraps lex lambda events and converts it into an object so you don’t have to remember string keys. All you have to do is pass your event to LexInputEvent.

Here is how pylexo works. For more detailed usage and auto-complete on Slots and Sessions, please visit pylexo documentation at Github

to install

pip install pylexo
import pylexo

def handler(event, context):
    pylexo_event = pylexo.LexInputEvent(event)
    print("messageVersion:   {}".format(pylexo_event.messageVersion))
    print("invocationSource: {}".format(pylexo_event.invocationSource))
    print("userId:           {}".format(pylexo_event.userId))
    print("PickupTime:  {}".format(pylexo_event.currentIntent.slots['PickupTime']))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s