The Intel IoT Examples Datastore is intended to provide a simple data store for sample applications that are part of the Intel IoT Starter Kit examples.
It is a Node.js* application written using Express* (https://github.com/strongloop/express). It uses a Redis* (http://redis.io) data store.
Although this data storage application is developed to deploy on Microsoft* Azure*, IBM* Bluemix*, or Amazon Web Services* (AWS) Elastic Beanstalk*, since it is based on commonly used open-source modules, it should be easy to deploy on many different cloud hosts.
The Intel IoT Examples Datastore application provides a simple REST API that allows authorized callers to store either log data or incremental counter data.
It exposes two sets of routes, both using basic token authentication.
To authorize, provide the AUTH_TOKEN
you set in the X-Auth-Token
HTTP header.
Multiple clients can share the same Intel IoT Examples Datastore by simply using a different route key for each application.
The counter routes are used to increment an increasing counter.
GET /counter/:key
- gets the current value of a counterGET /counter/:key/inc
- increments a counter by 1
The logger routes wrap Redis* lists, and are used to keep a linear backlog of values.
GET /logger/:key
- gets the latest value of a logPUT /logger/:key
- adds a value to a log (value
parameter in the POST body)GET /logger/:key/all
- returns all values of a log
To install the application dependencies, use the following command:
$ npm install
You also need to have Redis* installed. For more information, see the Redis* download page:
Primary configuration for the application takes the form of the following ENV
variables:
REDIS_URL
- the URL to use for Redis* communicationREDIS_AUTH
- authentication token for the Redis* backendPORT
- port to serve the application on (defaults to3000
)AUTH_TOKEN
- authentication token for clients to use
This guide covers setting up a deployment environment for the Intel IoT Examples Datastore on Microsoft* Azure*.
For other platforms, refer to the platform documentation.
Before we begin, ensure you have a Microsoft* Azure* account:
https://portal.azure.com/signin/index
- Click New and select Web + Mobile > Web App.
- Enter the name for your new web application.
- Click Create.
Your new web application is created.
- Click New and select Data + Storage > Redis Cache.
- Enter the name for your new Redis* cache.
- Click Create.
Your new Redis* cache is created.
- In the left sidebar, select Redis Caches and click the name of the new Redis* cache you created in the previous step.
- Select All settings > Properties.
- Write down or copy the value in the HOST NAME field so you can use it for the
REDIS_URL
setting for the web application. - Select All settings > Access keys.
- Write down or copy the value in the PRIMARY or SECONDARY field so you can use it for the
REDIS_AUTH
setting for the web application. - Select All settings > Access Ports.
- Set the Allow access only via SSL option to No.
- Click Save.
- In the left sidebar, select Web Apps and click the name of the new web application you previously created.
- Select All settings > Application settings.
- Scroll down to the App settings section.
- Specify
REDIS_URL
by typing the value from the HOST NAME field above. - Specify
REDIS_AUTH
by typing the value from the PRIMARY field above. - Specify
AUTH_TOKEN
by typing whatever shared secret key you want. - Click Save.
Note: you don't need to set PORT
, as the Microsoft* Azure* platform does that automatically.
- In the left sidebar, select App Services and click the name of the new web application you previously created.
- Click Settings.
- Click Deployment Source.
- Click Choose Source.
- Click External Repository.
- Click in the Repository URL field, and enter the following value: https://github.com/intel-iot-devkit/intel-iot-examples-datastore
- Click OK.
This means your application has been deployed to the Microsoft* Azure* cloud.
This guide covers setting up a deployment environment for the Intel IoT Examples Datastore on IBM* Bluemix*.
For other platforms, refer to the platform documentation.
Before we begin, please ensure you have an IBM* Bluemix* account:
https://console.ng.bluemix.net/
- Choose the Space where you want to add a new web application, or create a new one.
- Click Create Application.
- Scroll down to Cloud Foundry Apps and choose Node JS SDK.
- Fill in your app details.
- You will be redirected to the Getting Started page and your app will start, once there, click on Connections and click on Connect New.
- Search Redis in the filter bar at the top of the page and click on Compose for Redis.
- Currently there is only one plan to choose from, head to the bottom of the page and click Create.
- When you are prompted to restage the application, click on the Restage button.
- Once restaged click on the overview tab to take you back to the overview.
- Scroll to the bottom of the page and click on the Add GIT Repo and Pipeline button. If you have not already added an alias to your IBM ID a new window opens up, add a new alias, accept the terms and click Create. This alias needs to be lowercase.
- Once your alias has been created a confirmation page will show. Click Continue.
- Click on the Add GIT Repo and Pipeline button again, ensure that Populate the repo with the starter app package and enable the Build & Deploy pipeline is checked and click Continue.
- Once your GIT repo has been created you will be shown a success page, click Close.
- Your new GIT url is shown in the bottom right of the page.
In the directory you're using for this repository, use the command line to run the following Git* command that adds an IBM* Bluemix* server for deployment:
git remote add bluemix <GitURL>
where <GitURL>
is the value displayed at the top right of the Overview page.
Now you are ready to deploy the application.
To deploy your web application, run the following Git* command:
git push bluemix master -f
You are prompted for your IBM* Bluemix* username and password.
Once the operation is complete, your application has been deployed to the IBM* Bluemix* cloud.
Note: it may take a moment for your web application to restart.
This guide covers setting up a deployment environment for the Intel IoT Examples Datastore on AWS* using Elastic Beanstalk*.
For other platforms, refer to the platform documentation.
Before we begin, please ensure you have an AWS* account:
To deploy the Intel IoT Examples Datastore on AWS* using Elastic Beanstalk*, you must first install the EB CLI* tools as explained below:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html
In the directory you're using for this repository, use the command line to run the following EB CLI* command that creates a new AWS* application:
eb init
When prompted for the Elastic Beanstalk* region, enter the number of the region you wish, or choose the default.
When prompted for the Elastic Beanstalk* application to use, enter the number corresponding to the Create new Application option.
When prompted, enter y if you want to set up an SSH connection to your instances. Enter n if you do not want to set up an SSH connection.
Now, you can create your running environment by entering the following command:
eb create
When prompted for the Elastic Beanstalk* environment name, enter the name of the environment. If you want to accept the default, press Enter.
When prompted for a CNAME prefix, enter the CNAME prefix you want to use. If you want to accept the default, press Enter.
Most of the configuration settings are automatically determined by the Intel IoT Examples Datastore application itself when running under AWS* Elastic Beanstalk*. To set AUTH_TOKEN
, enter the following command:
eb setenv AUTH_TOKEN=<your token>
where <your token>
is your actual authorization token.