arqam
arqam

Reputation: 3809

Hosting a Chatbot Program in AWS Lambda

I am a developer and new to the system engineering part, so still getting my concept clear.

I need to deploy my chatbot in Lambda and host it using API Gateway, but following conceptual problem is arising.

I have a chatbot built using simple AIML. I created it on python and its working properly. For those who don't know of AIML, here I create an image of the AIML kernel : k = aiml.Kernel() and then as the conversation flow happens this kernel image is important for the conversation.

In my system, at an instance I just have one image of the kernel and things are good. But when I host this python program to Lambda and deploy it using API Gateway, for each request I will have a new image of the kernel, and my program will not function properly.

In a chatbot the conversation is happening at runtime, and and past conversation data is important, but if I am using API Gateway to trigger the Lambda function each time the user writes a new line, then every time a new image will be created of the kernel.

One option which I found was storing the user's session and conversation in a database. But in runtime if I am chatting, then the retrieval of past conversation and have the past conversation in the new image of kernel doesn't sounds a good way to go.

Or, even if we store the past conversation and send to the Lambda function using some JSON payload, then also since a new image of Kernel will be created by API Gateway, I have to run all the past conversation first and then only get the response for the new dialogue in the chat.

IN SHORT : How can I have one image of the kernel in the Lambda function, and get output using API Gateway, where the API is called multiple time for the same image of lambda function.

Or even if you know the general idea, how most online chatbots process and give responses, then that will also be very helpful.

Upvotes: 0

Views: 487

Answers (2)

Abhishek Raj
Abhishek Raj

Reputation: 512

The best way could be to use inbuilt data structures to maintain such conversations.
You need to run the whole thing essentially.
However, appropriate mapping to reach quickly to the desired o/p may enhance/optimize your result.

Upvotes: 1

K Mo
K Mo

Reputation: 2155

To answer your actual question, yes. You can create your kernel image outside of the lambda handler function. This means that the image will only be created at the point a new lambda container is spun up and won't be recreated at every invocation.

If prior conversation is important, then I feel I should warn you about some of the pitfalls of this approach though.

Lambda containers will die if no new requests are received (approx. half hour, but AWS doesn't specify this and can change it at any time).

Lambda containers will be recycled periodically, even if they are being used.

If you have multiple conversations, you can't assign a specific lambda container to a particular user.

Upvotes: 1

Related Questions