Amazon Lambda : VoiceWorx Integration
Objective
This guide will help you to quickly connect to Amazon Lambda and create various methods to execute Lambda functions and get the function output. The purpose is to demonstrate how easy it is to integrate Amazon Lambda to the VoiceWorx platform.
Pre-requisites
An active AWS Account
You should have an active AWS Account. If you do not have it, you can create an AWS account at https://portal.aws.amazon.com/billing/signup#/start
AWS Accounts Include 12 Months of Free Tier Access
At least one Lambda Function
If you do not have any Lambda function, you can follow this document on how to create a lambda function. Or for detail information, you can run through this Run a Serverless "Hello, World!" tutorial.
If you would like to refer to the introduction video of Lambda, you can watch this getting started video at https://youtu.be/eOBq__h4OJ4
Access Key, Secret access key and AWS Region Name To be able to connect to Amazon Lambda from the VoiceWorx platform, one IAM user is required and user should have permissions to view and execute Amazon Lambda functions. It is recommended to have IAM policy named AWSLambdaFullAccess be assigned to the user.
For more information on creating IAM users and assigning policies, refer to the AWS official documentation https://aws.amazon.com/premiumsupport/knowledge-center/create-access-key/
You can also refer to the simplified VoiceWorx documentation at https://docs.voiceworx.ai/aws-iam-users
A VoiceWorx Account
For steps to create a VoiceWorx account, follow the steps at https://docs.voiceworx.ai/general/voiceworx-create-account
Steps
To proceed with these steps, you should have all the pre-requisites satisfied. If you are missing something, please go back and make sure you satisfy all of them. For this particular demo, we strongly suggest that you create a lambda function as guided in this document.
Once done, you are ready to get started using VoiceWorx platform with Amazon Lambda.
Step 1 Connect to Amazon Lambda
Login to the VoiceWorx portal at https://portal.voiceworx.ai
To Configure Lambda, browse to: Integration > Connect System > Connect External System in the VoiceWorx platform and select options as shown below.
Once you click on “Connect System” button, you will be redirected to the configuration screen where you need to provide connection information as shown below.
If you do not have this information ready, please refer to the pre-requisites #3
The table below explains each of the inputs shown on this screen.
Input
Information
Service Instance Name
You can give any value of your choice.
Consumer Key
This is your AWS Access key ID
Consumer Secret
This is your AWS Secret access key
Region
AWS Region Name. Your Lambda functions should be in this region.
Fill the required information and click on “Validate and Save Settings” button, this will validate the details and if it is correct, integration will be saved, and you will be redirected to the integrations listing page as shown below.
Step 2 Create an App for Amazon Lambda
To create a skill, browse to Custom Apps > Manage Apps and click on New Custom App button as shown below.
You should see a small popup as shown below.
Input
Information
Name
You can give any value of your choice.
Custom App Type
Select Search
Category
Default
Click on save, this will create an app and you should see a screen as shown below,
This shows that an app is successfully created, and you have various options like setup data sources. This is explained in next step.
Step 3 Create a Data Source
To follow this step, make sure you have completed above Step 2. If not please go back and do it.
A Data Source connects the app with the Lambda integration we did in Step #1. Once you have a skill created, you can go to Data Sources by clicking on “Data Sources” tab.
Now you should see screen as shown below.
To create a data source, Click on ‘Create New Data Source’ button and you should see a popup screen as shown below
Give a name of your choice and make sure you select the Lambda integration that you have created in Step 1 and click on Save.
Once a data source is created, you are ready to start creating various methods.
Step 4 Create Methods to fetch the data from Amazon Lambda
To use this step, make sure you have completed previous step. If not go back and complete it.
Methods allows you to execute the Lambda function. To access the methods, click on the “Methods” tab which is next to the “Data Sources” tab.
As of the publication date of this document, the VoiceWorx platform supports following Lambda methods,
Get Functions
Execute Function
Depending on requirement, you will have to use an appropriate method, this document will explain each of these methods with an example.
Let’s start with a use case.
Scenario/ Use Case (Contact Finder):
You have a Lambda function which takes name as an input, searches for the contact information for the provided name and returns phone number as an output.
You want to find Phone Number of your friend Rose. For this, you can use ExecuteFunction method as explained below.
Method: ExecuteFunction
This method requires two parameters as explained below.
Parameters:
Parameter
Sample Value
Info
FunctionName
ContactFinder
(Select from the drop-down list: the one you created in the prerequisite section)
Lambda function name.
Version
Select Lambda Function Version.
The default is $LATEST
The version of the Lambda Function
Payload
{ "name": "rose" }
Input parameter(s) for the Lambda Function
Other than these two parameters, you need to provide the following standard inputs
Parameter
Info
Method Name
ExecuteMethod
You can give any name. This name will be displayed in the methods list.
Request Type
ExecuteMethod
This is the method that you are using
Parameters
As explained in the previous table
Result Type
Record (Auto Selected)
It indicates that the method can return one or more records
Record JsonPath
Each method returns data in json format and to pick any specific information from the json, we need to specify the Record JsonPath so Voice Worx platform will pick that data in consideration while displaying results.
Example: $.[*]
This selects all the records that is returned.
Result Template
Let’s assume that the following json represents one record.
{
"name": "Rose",
"phone": "(512) 757-6001",
"country": "USA"
}
Now, you want to select name, then you can provide Record Template as
Phone number of {{Name}} is {{phone}}
Note:
Anything written in between {{ }} is represented as a json field and it’s case-sensitive.
Empty Result Template
Sorry, the record could not be found. How else can I help you?
Now, you can save and test the method to see the method is able to fetch data from Lambda function.
Sample Response: (Dependent on Lambda Function output)
{
"name": "Rose",
"phone": "(512) 757-6001",
"country": "USA"
}
Method: GetFunctions
This method returns all the available Lambda functions in your account for the given Region.
Parameters: Not required
Parameter
Info
Method Name
GetFunctions
You can give any name. This name will be displayed in the methods list.
Request Type
GetFunctions
This is the method that you are using
Parameters
As explained in the previous table
Result Type
Records (Auto Selected)
It indicates that the method can return one or more records
Record JsonPath
Each method returns data in json format and to pick any specific information from the json, we need to specify the Record JsonPath so Voice Worx platform will pick that data in consideration while displaying results.
Example: $.[*]
This selects all the records that is returned.
Result Template
Here are the available functions: {{functionName}}
Note:
Anything written in between {{ }} is represented as a json field and it’s case-sensitive.
Empty Result Template
Sorry, the record could not be found. How else can I help you?
Sample Response:
[
{
"CodeSha256": "Zoi4TT7+rac74irUovU5MfPzU8fxnRmdZQbujxkvU78=",
"CodeSize": 380,
"DeadLetterConfig": null,
"Description": "",
"Environment": null,
"FunctionArn": "arn:aws:lambda:us-east-2:939063855410:function:ContactFinder",
"FunctionName": "ContactFinder",
"Handler": "lambda_function.lambda_handler",
"KMSKeyArn": null,
"LastModified": "2020-08-07T20:41:58.491+0000",
"LastUpdateStatus": null,
"LastUpdateStatusReason": null,
"LastUpdateStatusReasonCode": null,
"Layers": [],
"MasterArn": null,
"MemorySize": 128,
"RevisionId": "4d001c08-5bdc-48de-b7c6-ec5bd3d85f5c",
"Role": "arn:aws:iam::9390636344510:role/Role_Lambda",
"Runtime": {
"Value": "python3.8"
},
"State": null,
"StateReason": null,
"StateReasonCode": null,
"Timeout": 3,
"TracingConfig": {
"Mode": {
"Value": "PassThrough"
}
},
"Version": "$LATEST",
"VpcConfig": null
}
]
Create Intents
Now Create Intents for each method:
Fill the following details:
Name: ExecuteIntent
Intent Type: Search
Intent Action: Execute Method
Data Source: Lambda DS
Data Source Method: ExecuteMethod
Name: GetFunctionsIntent
Intent Type: Search
Intent Action: Execute Method
Data Source: Lambda DS
Data Source Method: GetFunctions
Create Utterances
Create Utterances to invoke the intent. Utterances are short keywords that are used to invoke the intents created. In the Utterances tab, make sure that the correct intent is selected in the drop down. Click on Create New Utterances and provide details as shown below:
For example, if you are going to create utterance for GetFunctionsIntent, make sure the intent is selected, Click on Create New Utterance and fill the details and Save.
A sample utterance for ExecuteIntent is also shown below.
Create Inputs
Now create Input for the intents:
Name: ExecuteInput
Custom App: Lambda
Custom Intent: ExecuteIntent
Data Source : Lambda DS
Data Source Method: ExecuteMethod
Name: GetFunctionsInput
Custom App: Lambda
Custom Intent: GetFunctionsIntent
Data Source : Lambda DS
Data Source Method: GetFunctions
Create Publish Profile and Publish
Now that all components of the app have been set, let us create publish profile and publish the app to Lex Bot.
Go to the publish tab and click on Add App Publishing.
Fill in the following details in the resulting screen.
External App Name: Lambda
Skill Type: Search
Channel: Amazon Lex
Version: Lex V1
Messages: All Messages shall be auto-populated. You can add/ edit them if not present.
Click on Save.
Once saved, now you can click on the Actions to Publish to the selected Channel i.e. lex in our case.
You will be directed to following screen, where you can select the Lex Account to which you want to deploy the bot.
Click on Publish to V1 and on success you’ll get following screen. You can now click on Go to Lex Skill and test the bot in the Amazon Lex Chatbot.
Here are some sample results:
Congratulations, you’ve successfully completed VoiceWorx integration with Amazon Lambda.
Last updated