Example: Create a Lex bot in AWS

The process of creating Lex V2 bots is documented by Amazon. Since the process could change, refer to Amazon documentation when creating chat bots. This example explains how to create a simple bot that books trips. To create this bot, use the Bots interface in Amazon Web Services (AWS).  

Start creating your bot by defining the name, description and some basic information.

Create an Amazon Lex V2 bot

  1. Sign in to the AWS Management Console and open the Amazon Lex console at https://console.aws.amazon.com/lexv2/home 
  2. Click Create bot.
  3. Under Creation method, select Create.
  4. Under Bot configuration, give the bot a name and an optional description.
  5. Under IAM permissions, choose a role that defines permissions for the bot.
    Note
  6. This role provides Amazon Lex permission to access other AWS services, such as Amazon CloudWatch. You can have Amazon Lex create the role, or you can choose an existing role with CloudWatch permissions. To create a custom role, use the IAM console. 
    • Create a role with basic Amazon Lex permissions
    • Use an existing role
  7. Under Children’s Online Privacy Protection Act (COPPA), choose the appropriate response.
  8. Under Idle session timeout, choose the duration that Amazon Lex V2 keeps a session with a user open. Amazon Lex V2 maintains session variables for the duration of the session so that your bot can resume a conversation with the same variables.
  9. (Optional) Under Advanced settings. add tags that help identify the bot, and can be used to control access and monitor resources.
  10. To create the bot and continue to adding a language, click Next. The Add language to a bot page opens.
  11. Add language to the Amazon Lex V2 bot

    1. Under Select Language, choose the appropriate language for the bot.
    2. (Optional) Add a description to associate with the language selection.
    3. Under Voice interaction, select the text-to-speech voice that your bot uses to interact with users.
    4. (Optional) Under Voice Sample, to preview how your voice sounds, add an example sentence or phrase and then click Play.
    5. Under Intent classification confidence score threshold, set the value that Amazon Lex uses to determine whether an intent is the correct intent.
      Note: You can adjust this value after you test your bot.
  • To add additional languages, click Add another language and repeat steps 1-4.
  • After you add all languages for the bot, click Done. The Intent editor opens.
  •  

    1. Log in to Amazon Web Services (AWS) and navigate to the AWS services page.

    2. Under Find Services, select Amazon Lex.

    3. On the Amazon Lex page, click Get Started.

    4. On the Create your bot page, select BookTrip. This bot is a sample bot that books trips.

    5. In the Bot name box, accept BookTrip as the default name, or type a different name.

    6. For this example, set COPPA to Yes.

    7. Click Create.

      Note: A page about the new bot appears. It allows you to define actions that the bot performs. These actions, called intents, are logical paths that the bot can take to interact with users. 

      For each intent, you must define utterances and slots:

      • Utterances are phrases that the bot can recognize, to invoke an intent (action).
      • Slots define any information the bot carries out in an intent.

      The template that this example is based on automatically added two intents. One to book a car (BookCar), and another to book a hotel (BookHotel).

      It added utterances to recognize phrases a user might say. When booking a car, the bot listens for “Make a car reservation,” “Reserve a car,” or “Book a car.” In response to any of those phrases, the bot prompts for the details it needs to make a reservation. Those details (called slots) prompt for city, pick-up date, return date, and so on. Information collected by slots can be passed to Architect.

      Each slot has a Slot type that defines how data in the slot is recognized and handled. For example, if you select AMAZON.DATE, the bot converts words that represent dates into a date format. When passed to Architect, slot data is converted to string format.

      Each slot in an intent has at least one prompt message. A prompt is often a question that a user must respond to, so that the bot can collect input data. Also, messages can be informational, not requiring a response. It is up to you, as a bot designer.

    8. In this example, the slots and prompts are already set up. Let’s test them. Type Hi in the “Chat to your bot” box. The bot doesn’t have an utterance that matches “Hi,” so it responds, “Sorry, what can I help you with?”

    9. In the chat box, type Book a car. The bot has an utterance to match, so it responds by prompting for the information defined by its slots.

    10. When you finish testing, click Build.

    11. Click Publish. Publishing a bot makes it available to use in Architect.

    12. The system prompts you to create an alias. This name is a pointer to a specific version of a bot. For more information, see Versioning and Aliases in the Amazon Lex Developer Guide. Since this is the first version of our bot, type FirstAlias in the Create an alias box. Later you use this name to refer to the bot in Architect.

    13. Click Publish.

    14. Wait for the operation to complete.