This application is a heart rate measurement tool using Fitbit. Heart rate is analyzed using Fitbit API, and notification is sent to LINE talk room if threshold is exceeded.
Applications are configured in a serverless architecture and work on AWS Lambda.
The development environment can be built with Docker.
Docker consists of the following containers.
-
dokidoki_watch-app
container- Alpine base
- NodeJS v4.3.2
-
dokidoki_watch-db
container- MySQL v5.7
Please open dev.fitbit.com and create a new application.
OAuth 2.0 Application Type
must be set to Personal
.
$ docker-compose build
$ docker-compose up
# For application settings, please edit `config/default.json` (or `development.json`, `production.json`).
$ npm run sequelize db:migrate
Open the http://localhost:3000/ in your browser. In API console, you can try the Fitbit API.
If you want to start Express without going through Docker, please execute the following command.
$ npm run watch
Deploy flow is same as aws-serverless-express
package.
Create a stack with CloudFormation.
$ mysql -u {USER} -p -h {HOST} -e "CREATE DATABASE {DATABASE}"
$ npm run sequelize -- --env production db:migrate
$ npm run config <accountId> <bucketName> [region]
$ npm run setup
Unfortunately, CloudFormation does not support scheduled Lambda events. Trigger must be set manually.
- Open
DokiDokiWatchHeartrateChecker
function on Lambda console. - Open the
Triggers
tab. - Open the
Triggers
tab and clickAdd triger
. - Set trigger properties.
- Trigger type: CloudWatch Events - Schedule
- Schedule expression: rate(5 minutes)
- Enable trigger: Check
This completes the setting.
Also, in order to connect to MySQL from Lambda, we strongly recommend VPC setting of Lambda function (VPC setting is not done in above setup)
You need to create a database first. Please match name specified in config/database.json
.
Please synchronize Fitbit. If application is set up correctly, you can check the execution result on CloudWatch Logs.
$ npm run package-upload-update-function
$ npm run delete-stack