Options
All
  • Public
  • Public/Protected
  • All
Menu

aws-lex-proxy

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

version travis build codecov coverage Codacy Badge dependency status MIT License semantic-release Commitizen friendly stability-stable Greenkeeper code style

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:

  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
  3. Change package.json -> config -> profile to your profile name
  4. Change package.json -> config -> s3BucketName to your bucket's name
  5. Change src/bin/lambda.ts BOT_ALIAS and BOT_NAME to your values
  6. 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

Architecture

Architectural Diagram