GenAI Powered Chatbot Using Bedrock and Lex

GenAI Powered Chatbot Using Bedrock and Lex

Ever wondered how to build your own AI-powered chatbot without diving deep into the complexities of machine learning? Well, you're in luck! Today, we'll craft a chatbot for booking a adventurous trip to Jurassic Park. Yes, you read that right! And we’ll do this using Amazon Bedrock and Lex in just 15 minutes. Let's get started, fellow tech adventurers!

Step 1: Enable Your Models in Amazon Bedrock

Before we bring our Bot to life, make sure to enable the following models on Amazon Bedrock:

  • Claude 2.1: Known for its sharp understanding and witty comebacks.
  • Claude: Excellent for nuanced language understanding.
  • Titan Embeddings G1 - Text: Perfect for extracting deep semantic meanings from text.

For those, who are new to Bedrock, search for Bedrock in the services. Once, in there, please navigate to Bedrock configurations and click on Model access.

Look for one of the model like Titan Embeddings G1 - Text. Click on the option "Available to request", it will open a small pop up window, click on the link "Request model access"


Access the model activation interface in your Amazon Bedrock console. Here, you'll find options to enable various models. Select "Titan Embeddings G1 - Text", "Claude", and "Claude 2.1" from the available list of models.

Click on the 'Next' button to proceed. If this is your first time activating models, you will be prompted to enter your company details. For testing purposes, you can enter placeholder information in these fields.

After entering your details, click the 'Submit' button to finalize the setup. It may take up to five minutes for the models to become fully active. This is a normal part of the process as the system configures and enables the selected models.

Once the models are enabled, you will see them listed in your console's model management section, indicating that they are ready for use.

Step 2: Create Your Knowledge Base

Our chatbot needs brains, and what better brains than a knowledge base built directly from Jurassic Park's own guides? Here’s how:

Files: https://github.com/dishu2511/JurassicParkChatBot.

The files mentioned above will act as the Knowledge Base documents, please clone/copy the files.

  • Store Your Documents: First, ensure your Jurassic Park documents are uploaded to an S3 bucket in the same account and in the same region.
  • Create the Knowledge Base: Navigate to Knowledge Bases under Builder tools


Click on Create dropdown and select the option of Knowledge Base with Vector Store


Select the option to create a new IAM role and choose an S3 bucket as the data source. Click 'Next' to proceed to the following page, where you should click on 'Browse S3' and select the S3 bucket where the files have been uploaded.


Next, it will take you embeddings selection model page, select Titan Embeddings G1 - Text v1.2 and Vector Database option as default.

Next, click to Create the Knowledge Base, it may take few minutes to create the Knowledge base.

  • Sync'ing the Knowledge Base: Once, the Knowledge Base is created, Go to the Data Source under the newly created Knowledge base and select the option to Sync the files.

Once, the sync is completed, you should be able to see 5 files under Source files, as we copied 5 files in the S3 bucket.

So, by now we have the knowledge base successfully created.

Step 3: Crafting the Chatbot with Amazon Lex

Now, onto the fun part—building our chatbot, affectionately named JurassicParkBookingBot.

Create the Bot:

  • Go to the Amazon Lex console.
  • Click on "Create Bot".
  • Choose Traditional Bot method
  • Name your bot JurassicParkBookingBot.
  • Choose the option to create an IAM role, if you haven't got a role already
  • Choose No for Children’s Online Privacy Protection Act (COPPA)
  • Keep everything else as default and create the Bot

Create the Intents:

Next we need to create the intents. Although we can design multiple intents based on the chatbot’s requirements, let’s keep it simple for this use case. We will create two intents: a simple greetings intent and a general inquiry or Question and Answer intent that will link to the Knowledge Base we have created.

1. GreetingIntent:

  • To create this intent, please select "Add empty intent"

  • Add typical greetings like "Hello", "Hi there!", "Greetings!".
  • Configure responses such as "Welcome to Jurassic Park! How can I assist your adventure today?"
  • Click on Save Intent

  • Next lets build this intent by click on Build on the top right corner of the console.

  • Once the build is finished, you will notice that it has already created two intents. GreetingIntent & FallbackInent. The FallbackIntent is to handle any queries or user inputs that do not match any of the other defined intents in the chatbot. Essentially, it serves as a safety net for when the chatbot fails to recognize or understand the user's intent.
  • Lets test this intent by clicking on the Test button.



So, as you can see, the chatbot at the moment has no idea about the Jurassic Park Knowledge Base we created. Hence, it FallBackIntent kicked in which is a default intent.

2. GeneralInquiryIntent:

  • This is where the magic happens. Link this intent to the knowledge base we created earlier.
  • To create this intent, please select "Use built-in intent"

  • Choose AMAZON.QnAIntent - GenAI feature, and name it GeneralInquiryIntent.

  • Next, please select Claude V2 for the model and copy and paste the Knowledge Base ID. Keep everything else as default.

  • Knowledge Base ID can be obtained from the Knowledge Bases console.


  • Next, lets build this intent.

Testing the Bot

Alright, we've hit an interesting part of our setup! We’ve got our Knowledge Base in place, supported by documents in an S3 bucket. Alongside that, we've crafted a Lex chatbot equipped with two main intents. Initially, our chatbot featured just the greetings intent, and during our early tests, it didn’t manage to handle queries about Jurassic Park. Now, with our second AI-powered intent that taps into the Knowledge Base, it’s time to see how it performs with these queries. Let’s run some tests and check out the responses!



With the integration of the Knowledge Base, the chatbot has started responding to all related queries. Now that the AI-powered intent is functioning with the support of the Knowledge Base, you'll find that the bot handles questions about Jurassic Park much more effectively. Feel free to test it further with a variety of queries based on the information in the documents to see how it adapts and responds.

Cleanup the resources

Once you've finished testing your chatbot and want to ensure that you're not billed further, here are the key AWS resources you should consider deleting or terminating:

  1. Amazon Lex Chatbot
  2. Amazon S3 Bucket:
  3. Knowledge Base
  4. OpenSearch Vector Database (Under Serverless)

This wraps up our blog for today, I hope this demonstration has been helpful and inspires you to explore further what you can achieve with AI-powered chatbots. Happy experimenting!

要查看或添加评论,请登录

Dinesh Sharma的更多文章

  • From Bicycle to Spaceship: Navigating the Cloud Transformation Journey

    From Bicycle to Spaceship: Navigating the Cloud Transformation Journey

    Cloud transformation is like a journey one that takes you from the streets of your neighborhood to destinations far…

    6 条评论
  • re:Invent 2024: Day 4 Recap

    re:Invent 2024: Day 4 Recap

    Keynote Highlights from Werner Vogels: Lessons in "Simplexity" Werner Vogels’ keynote at AWS re:Invent 2024 was, as…

  • re:Invent 2024 Day 3 Recap

    re:Invent 2024 Day 3 Recap

    It’s Day 3 of AWS re:Invent, and the cloud conference rollercoaster is in full swing! Today was extra special because…

  • re:Invent 2024: Day 2 Recap

    re:Invent 2024: Day 2 Recap

    After the excitement of Day 1 at AWS re:Invent, which I recapped yesterday, the momentum only picked up on Day 2! Today…

    1 条评论
  • re:Invent 2024: Day 1 Recap

    re:Invent 2024: Day 1 Recap

    AWS re:Invent isn’t just an event, it’s a full-blown tech carnival where innovation meets collaboration, sprinkled with…

  • Farewell to AWS Services: A Nerdy Goodbye

    Farewell to AWS Services: A Nerdy Goodbye

    Well, folks, it looks like AWS has decided to play the role of the grim reaper for some of its services. In a move that…

    1 条评论
  • Drawing AWS with Python (No Art Skills Required)

    Drawing AWS with Python (No Art Skills Required)

    Gone are the days when updating architecture diagrams was a tedious task that often got pushed to the back burner In…

    5 条评论
  • Schedule Your Fargate Pods Organization-Wide Using a magic Lambda

    Schedule Your Fargate Pods Organization-Wide Using a magic Lambda

    Spoiler Alert! There are no magic Lambdas here, just a carefully crafted Lambda function designed to automate the…

  • Scaling Deployments with AWS Lambda

    Scaling Deployments with AWS Lambda

    Hello LinkedIn :) Recently, I've had the pleasure of diving deep into a fascinating use-case involving AWS Lambda and…

  • Exploring Public Service Hosting Options on EKS

    Exploring Public Service Hosting Options on EKS

    Today, we're diving into the increasingly relevant world of Amazon EKS to uncover various strategies for hosting public…

社区洞察

其他会员也浏览了