If you prefer a self-managed deployment, you can setup your own server running a node application and copy and use the files from basic-demo-self-deploy. With the endpoint created to received Skills event from Box, configure it with Box.
The automated way of deploying and hosting your skills code is by putting it on a lambda cloud function with one of the commercial cloud service providers. Using a tool called serverless, we can do that in a quick and easy automated script deployment, as long as one has the user token for a cloud service provider account with permissions to create lambda cloud functions. This way one doesn't have to log into the cloud service provider's dashboard and update their code on the cloud function through manual upload and restarting of the service.
As pre-requisites install the following locally on your developement machine:
- Node (we recommend node-8 because then your development and deployment environment would match. Once you download and install node, you get access to the npm CLI or command line interface/terminal for all the commands later on)
- Serverless ( hint: you may need to use sudo npm install )
Next generate your cloud provider keys to setup in serverless keys, through any provider of your choice:
- AWS Lambda -> console | instructions to create keys
- IBM Open Whisk -> console | instructions to create keys
- Google Cloud Functions -> console| instructions to create keys
- Microsoft Azure -> console | instructions to create keys
- Others provider options -> Kubeless, Spotinst, Auth0, Fn, etc
You can setup your local serverless to use your new keys with this sample command
Next, copy this git project locally
git clone https://github.com/box/box-skills-kit-nodejs.git
or download and unzip: https://github.com/box/box-skills-kit-nodejs/archive/master.zip
Finally, deploy serverless-demo-automated code using the Node CLI with a single command. Everytime you make change to the code, you need to rerun this command.
cd box-skills-kit-nodejs/boilerplate-skills/serverless-demo-automated
npm run deploy
You should see an output such as this-
npm run deploy
> [email protected] deploy /your-project-path/box-skills-kit/boilerplate-skills/serverless-demo-automated
> npm install; ./node_modules/.bin/serverless deploy
> [email protected] postinstall /your-project-path/box-skills-kit/boilerplate-skills/serverless-demo-automated
> npm link ../../skills-kit-library
up to date in 0.589s
/your-home-path/.nvm/versions/node/v9.4.0/lib/node_modules/skills-kit-lib -> /your-project-path/box-skills-kit/skills-kit-library
/your-project-path/box-skills-kit/boilerplate-skills/serverless-demo-automated/node_modules/skills-kit-library -> /your-home-path/.nvm/versions/node/v9.4.0/lib/node_modules/skills-kit-lib -> /your-project-path/box-skills-kit/skills-kit-library
removed 1 package in 4.768s
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
.....
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (13 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............................
Serverless: Stack update finished...
Service Information
service: my-quick-automated-demo
stage: dev
region: us-west-2
stack: my-quick-automated-demo-dev
api keys:
None
endpoints:
ANY - https://**********.execute-api.us-west-2.amazonaws.com/dev/my-quick-automated-demo
functions:
skill: my-quick-automated-demo-dev-skill
Use this endpoint https://**********.execute-api.us-west-2.amazonaws.com/dev/my-quick-automated-demo
to configure your skill with box. Everytime, a file is uploaded, moved or copied to one of the folder under the enterprise where your skill is enabled, your service would recieve an event, and you can see your code execution log, logging into your cloud portal.
You can improve the quality of your code by running formatting and unit-testing scripts. Simply type and enter-
npm run format
npm run test
A lambda cloud function is a short-lived server instance that only exists when it recieves an event, and shut down when it the request has been processed. This can helpful in case you skill deployment follows the following architectures, since it doesn't use any more or less of the uptime than required to process your request. However, you can also be running your own server with multiple nodejs services. In either case you would need to look at individual case of how long the processing needs to run, if it's synchronous or asychronous, and architect your services accordingly by as either of these models.