- Make sure MongoDB 3.4 is installed on your machine (we will need it to restore the movie dataset to MongoDB Atlas)
- Sign up at MongoDB Atlas or sign in into your existing Atlas account.
- From the Clusters page, build a new cluster if you don't already have one (using the Build a New Cluster button). Since we'll use AWS technologies only available in the us-east-1 (N. Virginia) region (as of November 2017), it's best if you create a cluster using the AWS cloud provider in that region.
- Select your cluster and press the Connect button. In the window that opens, click on Connect with the Mongo Shell and press the Copy button.
- Paste the value into the
/data/restore.sh
script and replicate the modifications done from the original script into the modified script (adding the--host
parameter, replacingmongodb:/
with thereplicaSet
value and adding the--gzip
parameter). Please check the mongorestore documentation for additional information. - From the
data
folder, run therestore.sh
script to restore the moviesDB database into MongoDB Atlas. - To follow least privilege access best practices, it is highly recommended to create a specific database user with only read/write access to the movies collection of the moviesDB database (see this screenshot for an example)
Review the setup instructions available in this blog post
This is the Lambda function used by our Lex chatbot to fulfill the intent and retrieve the list of movies featuring the actor/actress specified by the user.
- Sign in to MongoDB Atlas and retrieve the connection string of the cluster containing your moviesDB database and customize the username and password to match the credentials of a database user having read permissions on the moviesDB database (i.e.
read@moviesDB
permissions) (as a best practice, do not use your Atlas administrator account). - In the code/template.yaml file, fill out the
MONGODB_URI
environment variable with the connection string you just customized.
- Install Docker on your machine
- Install SAM Local on your machine
- Run
sh sam-invoke.sh
from Terminal to test your Lambda function locally. You can customize the values of thecurrentIntent
element of the event.json file to test different values.
- In AWS, create an S3 bucket. In code/sam-package.sh, replace
<S3-BUCKET-NAME>
with the name of the bucket you just created - In the following instructions, all the scripts use a
lex
profile so you can either:- create such a profile in your AWS credentials file. You will need to create an IAM user with the following permissions:
AWSLambdaFullAccess
,AmazonLexFullAccess
and the custom permissions available in this AWS Policy file. - or replace it with the
default
profile if your default AWS CLI user has full admin priviledges.
- create such a profile in your AWS credentials file. You will need to create an IAM user with the following permissions:
- Run
sh package.sh
from Terminal to package your SAM package. This will package your SAM package and upload it to your S3 bucket. - Run
sh deploy.sh
from Terminal to deploy your SAM package to AWS Lambda and API Gateway - Once the script has completed (without errors), sign in into the AWS Console and navigate the AWS Lambda section.
- You should see a LexMovieSearch Lambda function. Select it and use the event.json file to create a test event and test that the Lambda function works.
- Once you have validated that your Lambda function works, navigate back to the AWS Lex home.
- Select the SearchMoviesBot bot and in the Fulfillment section, select AWS Lambda function and select the
LexMovieSearch
lambda function. An Add permission to Lambda Function window may pop up, press OK to confirm. - At the top of the page, press the Build button twice
- Use the chat bot and enter the following prompt: Looking for a movie. This should kick off the SearchMovies intent we just configured. You can then test the following answers to the consecutive questions prompted by the bot:
cOmedY
anGeliNa JOLIE
- 0
- You should get the following answer from the bot, coming right from your MongoDB Atlas database:
Angelina Jolie played in the following comedy movies: Hackers (1995), Mojave Moon (1996), Playing by Heart (1998), Pushing Tin (1999), Life or Something Like It (2002), Mr. & Mrs. Smith (2005)