aws-lex-proxy v1.0.0
aws-lex-proxy
NPM library providing proxy functionality for those needing AWS Lex to be used outside AWS infrastructure without aws-sdk in deployable artifact
Table of Contents
Motivation
As AWS Lex does not provide external API endpoint when being setup it results in only two possibilities of using the NLP product:
- deploying exclusively on AWS infrastructure (Lambda) to access the functionality
- using AWS SDK
This is meant to provide third option:
- vanilla HTTPS endpoint to query Lex.
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.
Installation
npm i aws-lex-proxySetup
You can either setup the infrastructure in one of the following ways:
1. Create manually via Console API a stack similar to below architecture diagram as Gateway -> Lambda -> Lex with API Gateway Request Template for application/json and Lambda content as in usage below.
2. Clone this package's GitHub repository and
- Change
package.json->config->profileto your profile name - Change
package.json->config->s3BucketNameto your bucket's name - Change
src/bin/lambda.tsBOT_ALIASandBOT_NAMEto your values - Run
npm run setupwill deploy the CloudFormation stack and in output you will have the API endpoints to use with your application
Usage
NOTE: 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 handlerDocumentation
You can find the documentation here
Architecture

8 years ago