service that generates search content for the requested course
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
- Clone this repository locally
- Run
npm install
oryarn
in the root directory - Configure several environment variables:
-
S3_CACHE_BUCKET_NAME - AWS bucket name to cache generated files
-
S3_ACCESS_KEY_ID - AWS access key to access the cache bucket
-
S3_SECRET_ACCESS_KEY - AWS access secret to access the cache bucket
optional environment variables:
-
S3_REGION - AWS bucket region. Default is
us-east-1
-
IP - IP for the express app. Default is
127.0.0.1
-
PORT - Port for the express app. Default is
3036
- Run
npm start
oryarn start
to run application locally
Application is wrapped as a serverless function (check serverless.js). That's why you can also run it with serverless CLI locally.
If you are using Visual Studio Code you can use two existing launch configurations. To launch tests you can use Run tests
configuration without any changes. If you want to run the app use Launch Program
configuration but first you have to fill proper values for the next environment variables:
"env": {
"S3_ACCESS_KEY_ID": "accessKey",
"S3_SECRET_ACCESS_KEY": "accessSecret",
"S3_CACHE_BUCKET_NAME": "bucketName"
}
Use node.js 7.x or higher
to develop and run the app.
NOTE: The application is an express app wrapped with serverless framework. If you are going to deploy an app as a lambda function do not use node.js
higher than 8.10
. At the moment of writing 8.10
is the latest version supported by AWS lambda.
To run tests execute npm run test
or yarn test
To get course search content you have to use /search-content
path and to specify course url in the query string. For instance:
http://localhost:3036/search-content?url=https://elearning.easygenerator.com/bf9a6632-9ce7-4007-92ca-0cb6fd1f7e29/
If you are using deployed AWS lamda app, you have to add x-api-key
(AWS Lambda API Key) header to the request with the proper API Key. API Key will be generated during the serverless deployment and can be checked in AWS Api Gateway for you Lambda function.
Application can be deployed as regular express.js
app. Don't forget to specify needed environment variables.
Application can be deployed as AWS Lambda function. You have to have serverless.js installed globally. To do this execute next command:
npm install -g serverless
Next use following command to deploy the app:
Windows PowerShell:
$env:AWS_BUCKET_SUFFIX="[AWS_BUCKET_SUFFIX]"; `
$env:AWS_DEFAULT_ROLE_ARN="[AWS_DEFAULT_ROLE_ARN]"; `
$env:AWS_ACCESS_KEY_ID="[AWS_ACCESS_KEY_ID]"; `
$env:AWS_SECRET_ACCESS_KEY="[AWS_SECRET_ACCESS_KEY]"; serverless deploy
Unix:
env AWS_BUCKET_SUFFIX="[AWS_BUCKET_SUFFIX]" \
env AWS_DEFAULT_ROLE_ARN="[AWS_DEFAULT_ROLE_ARN]" \
env AWS_ACCESS_KEY_ID="[AWS_ACCESS_KEY_ID]" \
env AWS_SECRET_ACCESS_KEY="[AWS_SECRET_ACCESS_KEY]" \
serverless deploy
where:
-
AWS_BUCKET_SUFFIX - is a bucket suffix to make it unique. May be your organization's domain, like
.example.com
-
AWS_DEFAULT_ROLE_ARN - AWS role that will be used by the function
-
AWS_ACCESS_KEY_ID - AWS access key that will be used by the serverless framework to deploy your function and create/access all needed infrastructure
-
AWS_SECRET_ACCESS_KEY - AWS access secret that will be used by the serverless framework to deploy your function and create/access all needed infrastructure
IMPORTANT: when deploying with serverless you can skip S3_CACHE_BUCKET_NAME, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY environment variables they will be initialized with variables listed above. You should also grant needed permissions to the user you are using for the deployment. For more information check serverless.js AWS credentials guide.
More information about serverless deployment you can find in the serverless.js documentation.
Deploying with serverless you can also specify build options. For instance you can specify stage you deploying to:
serverless deploy --stage production
or in case you don't want to output API Key to the console (usefull for builds with external CI tools) you should add --conceal
option:
serverless deploy --conceal --stage production