aws-lex-proxy
v1.0.0
Published
Proxy to connect external services to AWS Lex
Downloads
1
Readme
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-proxy
Setup
You can either setup the infrastructure in one of the following ways:
- Create manually via Console API a stack similar to below architecture diagram as Gateway -> Lambda -> Lex with API Gateway
Request Template
forapplication/json
and Lambda content as in usage below. - Clone this package's GitHub repository and
- Change
package.json
->config
->profile
to your profile name - Change
package.json
->config
->s3BucketName
to your bucket's name - Change
src/bin/lambda.ts
BOT_ALIAS
andBOT_NAME
to your values - Run
npm run setup
will 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 handler
Documentation
You can find the documentation here