As AWS Lex does not provide external API endpoint when being setup it results in only two possibilities of using the NLP product:
This is meant to provide third option:
This is achieved by setting up an microservice using AWS API Gateway and Lambda. The HTTPS endpoint will be the API Gateway that triggers Lambda which queries Lex and returns data. CloudFormation stack setup is provided with all needed commands.
npm i aws-lex-proxy
You can either setup the infrastructure in one of the following ways:
Request Template for application/json and Lambda content as in usage below.package.json -> config -> profile to your profile namepackage.json -> config -> s3BucketName to your bucket's namesrc/bin/lambda.ts BOT_ALIAS and BOT_NAME to your valuesnpm run setup will deploy the CloudFormation stack and in output you will have the API endpoints to use with your applicationNOTE: The proxy function takes in AWS SDK configured(if used locally during testing without IAM). This puts SDK version used at users discretion as long as it contains the LexRuntime functionality.
This is the Lambda function content
import LexProxy from 'aws-lex-proxy';
/// AWS SDK setup here
const BOT_ALIAS = 'AwesomeBotAlias';
const BOT_NAME = 'AwesomeBotName';
const handler = (event, context, cb) => {
const lexProxy = new LexProxy(BOT_ALIAS, BOT_NAME, awsSdk);
lexProxy.proxy(event, context, cb);
}
export default handler
You can find the documentation here
