Two updates to this story…


The one is that I managed to get entities (or as AWS Les refers to it, Slots) working contextually. I took cities, and gave it a Slot Type of Amazon European City. From here I could enter other City names, non-European and very unknown. Even fictitious names; and Lex could determine the name purely from context; even though the city name was not in Europe.

Below is my slot configuration.

Image for post
Contextual Slot Detection In Amazon Lex


Below is the code from an updated Lamda function in Python 3.8 performing the following:

  • Setting two session attributes
  • Catching the entity and the intent and return it in a message.

This code can serve as a basic framework for you to build out your integration and add intelligence, checks and advanced dialog management.

def lambda_handler(event, context):
entity = event["currentIntent"]["slots"]["Name"].title()
intent = event["currentIntent"]["name"]

response = {

"sessionAttributes": {
"key1": "value1",
"key2": "value2"
"content": "The intent you are in now is "+intent+"! And the entity is "+entity+"!"

return response

NLP/NLU, Chatbots, Voice, Conversational UI/UX, CX Designer, Developer, Ubiquitous User Interfaces.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store