First Simple Serverless ChatBot Experience with Amazon Lex and Lambda function

What will you learn?

What you need?


Amazon Lex is a tool for building conversational interfaces on AWS. Lex is effectively the technology used by Alexa, Amazon’s voice-activated virtual assistant which lets people control things with voice commands such as playing music, setting alarm, ordering groceries, etc. It provides deep learning-powered natural-language understanding along with automatic speech recognition. Amazon now provides it as a service that allows developers to take advantage of the same features used by Amazon Alexa. So, now there is no need to spend time in setting up and managing the infrastructure for your bots.

The best thing about ChatBot:

“Amazon Lex allows you to easily publish your bot to chat services directly from the Amazon Lex console, reducing multi-platform development efforts. You can configure the bot through the Console to create a callback URL to facilitate the integration. Rich formatting capabilities on Amazon Lex enable an intuitive user experience. Integration with Kik simplifies deployment and management of the Amazon Lex bot on the messaging platform.”

How does Amazon Lex work?

Building a bot on Lex is done through the AWS console. Start by selecting “Lex” from the list and clicking on “Get Started.” This is also a good time to read the “Getting Started with Amazon Lex” guide.

Let’s Implement ChatBot:

1. First start with Amazon Lex

  • Go to Amazon Lex
  • Click on “Get Started with Amazon Lex”
  • Now give the credentials as IAM user or you can also sign-in through root account credentials. If don’t have amazon account no worry we can create it through sign-up which free of cost.
  • Click on “Create button” for creating new ChatBot.
  • Now you can choose to create your own experience, or start with a template, or sample from the menu. Here we are choosing “Custom bot”.
  • Create a custom bot by providing following information:
    • Bot Name: SpotChatBot
    • Output voice: None, this is only a test based application
    • Set Session Timeout: 5 min
    • Add Amazon Lex basic role to Bot app: Amazon will create it automatically.Find out more about Lex roles and permissions here.
    • Choose no for COPPA.
    • Click on Create button, which will redirect you to the editor page.
    • Intent: Intent represents a goal, needed to be achieved by the bot’s user. In our case, our goal is to provide services to customers.
      • Here we are creating 1 intent name as “Spot Service”.
      • Click on “create Intent”.
      • Under “Add Intent” click “Create Intent” and give the name of Intent.
      • Click on “Add” for adding Intent for our ChatBot.
    • Utterances: An utterance is a text phrase that invokes intent. If we have more than one intent, we need to provide different utterances for them. Amazon Lex builds a language model based on utterance phrases provided by us, which then invoke the required intent.

      Provide some utterances to invoke the intent. An utterance can consist only of Unicode characters, spaces, and valid punctuation marks. Valid punctuation marks are periods for abbreviations, underscores, apostrophes, and hyphens. If there is a slot placeholder in your utterance ensure, that it’s in the {slotName} format and has spaces at both ends.

      For our example, we need a single intent “SpotService”. Some sample utterances would be:

      • I want to know about jobs at Us location
      • Can you please provide service on Automation
    • Slots: Each slot is a piece of data that the user must supply in order to fulfill the intent. Slots are an input, a string, location etc. that are needed to reach the goal of the intent. Each slot has a name, slot type, a prompt, and is it required. The slot types are the valid values a user can respond with, which can be either custom defined or one of the Amazon pre-built types.
      Map slots with their types and provide prompt questions that need to be asked to get valid value for the slot. Note the sequence, Lex-bot will ask the questions according to priority.
    • Prompt: A prompt is a question that Lex uses to ask the user to supply some correct data (for a slot) that is needed to fulfill an intent. e.g. Lex will ask “How can I help you like, services, jobs or events?” to fill the slot.
    • Fulfillment: Fulfillment provides the business logic that is executed after getting all required slot values, need to achieve the goal. Amazon Lex supports the use of Lambda functions for fulfillment of business logic and for validations.
      Now we have all necessary data gathered from the chatbot, it can just be passed over in lambda function, or the parameters can be returned to the client application that then calls a REST endpoint.

2. Start with Amazon Lambda function

Amazon Lex supports Lambda function to provide code hooks to the bot. These functions can serve multiple purposes such as improving the user interaction with the bot by using prior knowledge, validating the input data that bot received from the user and fulfilling the intent.

Steps for Creating Lambda Function:

  • Go to AWS Lambda and click on “Get started with AWS Lambda”.
  • Now give the credentials as Iam user or you can also sign-in through root account credentials. If don’t have amazon account no worry we can create it through sign-up which free of cost.
  • After navigating to AWS console, click on “Create Function” for creating new function.
  • Select blueprint as blank function and click next.
  • Give the details of as follows
  • Click on “create function”.
  • Now our console is ready for write the code.
  • FULFILLMENT CODE HOOK: This lambda function is invoked after receiving all slot data required to fulfill the intent
  • exports.handler = (event, context, callback) => {

    // when intent get fulfilled, inform lex to complete the state

    let response = {sessionAttributes: event.sessionAttributes,

    dialogAction: {

    type: “Close”,

    fulfillmentState: “Fulfilled”,

    message: {

    contentType: “PlainText”,

    content: “Thanks for service request. Mail us at if any queries are there .”




    callback(null, response);


  • Click on “Test” button for configuring the test event.
  • Write the test event and save it
  • We can configure our bot to invoke these lambda functions. We need to do this while configuring the intent as shown below:
  • Now click on “Build” for building the ChatBot.
  • Now ChatBot is ready for test

I hope you have understood the basic terminologies of Amazon Lex along with how to create a simple chat-bot using serverless (Amazon Lambda).

Get a complimentary 30 minute marketing consultation and an audit report from our expert who has been awarded by LinkedIn Pro as ‘Best of 2017 & 2016’ in various categories including – ‘Marketing Consulting’, ‘Digital Marketing’ and ‘Lead Generation’.

Learn how other organizations are partnering with us for turnkey marketing services and solutions impacting real business outcomes.

Roy Lingam CEO,Delphi USMLE. Chicago

NectarSpot team successfully re-branded and revamped our old website to a fast loading and aesthetically pleasing within a short time frame of four weeks. NectarSpot designers and developers created a distinct UI/UX landing pages that communicates our brand as an established brand identity helping us to get more conversions. Our end users appreciate the site’s unique and polished presentation through an informative, well laid-out content and beautifully designed pages that helps a seamless interaction . The team is extremely organized and communicative and working with their team was seamless and highly collaborative. Their team is both technically and creatively talented. After creating relevant landing pages and revamping the entire site, NectarSpot is helping us to generate qualified leads through Google Ads campaign. We see a definitive increase in key web metrics such as higher conversion rate, lower bounce rate and higher engagement. We would highly recommend NectarSpot to anyone looking to up-brand their digital identity and get qualified leads.
Read More Testimonials....

Ryan Frederickson ArT Wine Preserver

NectarSpot team executed the Quick and solid build of AMP website. Not afraid of small tweaks here and there. The team has, from the beginning of project, focus on conversion and provided a seamless workflow for my prospects to visit, educate and finally purchase on my e-commerce portal. They provided design, development on AMP framework and helped to host e-commerce portal on scalable and secure google cloud. We are looking forward to working with them in future for other projects as well.
Read More Testimonials....

Read more to gain insights from our blogs.
Receive latest marketing insights, data and inspiration by subscribing .

Start Your Project Today (100% Satisfaction Guaranteed)

  • NectarSpot Inc. is an integrated digital marketing agency specializing in Design & Development of Web, Mobile & Voice Applications.
    We excel in providing Optimization, Automation, PPC & Analytics services to high performing brands across industries.

    Contact us today at +1 630 999 (7768) or email at to know more.

Need help?

We are right here!