├── .gitignore ├── CODE_OF_CONDUCT.md ├── deployment ├── run-unit-tests.sh └── build-s3-dist.sh ├── source ├── services │ ├── jitr │ │ ├── test-setup.spec.js │ │ ├── package.json │ │ └── index.js │ ├── driversafety │ │ ├── package.json │ │ ├── lib │ │ │ ├── index.js │ │ │ ├── driver-safety.spec.js │ │ │ └── driver-safety.js │ │ └── index.js │ ├── notification │ │ ├── package.json │ │ ├── lib │ │ │ ├── index.js │ │ │ ├── notification.js │ │ │ └── notification.spec.js │ │ └── index.js │ ├── vehicle │ │ ├── package.json │ │ ├── index.js │ │ └── lib │ │ │ ├── vehicle.spec.js │ │ │ ├── vehicle.js │ │ │ ├── anomaly.spec.js │ │ │ ├── healthreport.spec.js │ │ │ ├── trip.spec.js │ │ │ ├── dtc.spec.js │ │ │ ├── trip.js │ │ │ ├── healthreport.js │ │ │ ├── dtc.js │ │ │ ├── anomaly.js │ │ │ └── index.js │ ├── anomaly │ │ ├── package.json │ │ ├── index.js │ │ └── lib │ │ │ └── index.js │ ├── dtc │ │ ├── package.json │ │ ├── lib │ │ │ ├── index.js │ │ │ └── dtc.spec.js │ │ └── index.js │ └── marketing │ │ ├── package.json │ │ ├── lib │ │ ├── index.js │ │ ├── marketing.spec.js │ │ └── marketing.js │ │ └── index.js ├── data-loaders │ └── dtc-generator │ │ ├── package.json │ │ ├── index.js │ │ └── loader.js └── resources │ └── helper │ ├── package.json │ ├── marketing-pois.csv │ ├── obd-trouble-codes.csv │ └── lib │ ├── metrics-helper.js │ ├── iot-helper.js │ └── dynamodb-helper.js ├── CHANGELOG.md ├── NOTICE.txt ├── README.md ├── CONTRIBUTING.md └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | **/dist 3 | **/open-source 4 | **/.zip 5 | **/.DS_Store 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. -------------------------------------------------------------------------------- /deployment/run-unit-tests.sh: -------------------------------------------------------------------------------- 1 | cd ../source/services/anomaly 2 | npm install 3 | npm test 4 | 5 | cd ../driversafety 6 | npm install 7 | npm test 8 | 9 | cd ../dtc 10 | npm install 11 | npm test 12 | 13 | cd ../notification 14 | npm install 15 | npm test 16 | 17 | cd ../vehicle 18 | npm install 19 | npm test 20 | 21 | cd ../marketing 22 | npm install 23 | npm test 24 | -------------------------------------------------------------------------------- /source/services/jitr/test-setup.spec.js: -------------------------------------------------------------------------------- 1 | const sinon = require('sinon'); 2 | const chai = require('chai'); 3 | const sinonChai = require('sinon-chai'); 4 | 5 | before(function() { 6 | chai.use(sinonChai); 7 | }); 8 | 9 | beforeEach(function() { 10 | this.sandbox = sinon.sandbox.create(); 11 | }); 12 | 13 | afterEach(function() { 14 | this.sandbox.restore(); 15 | }); 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [2.1.2] - 2021-05-31 9 | 10 | ### Added 11 | 12 | - Added Point In Time recovery and Encryption support for DynamoDB Table 13 | - Added API Gateway usage plan 14 | - Added cfn_nag suppress rules for Lambda VPC deployment and Reserved Concurrency 15 | 16 | ### Fixed 17 | 18 | - Removed unused dev dependency grunt 19 | 20 | ## [2.1.1] - 2019-12-20 21 | 22 | ### Added 23 | 24 | - upgraded lambda runtime to nodejs 12.x 25 | -------------------------------------------------------------------------------- /source/data-loaders/dtc-generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "connected-car-sim-engine", 3 | "description": "The simulation engine for the connected car solutions", 4 | "main": "index.js", 5 | "license": "ASL", 6 | "version": "0.0.1", 7 | "private": "true", 8 | "dependencies": { 9 | "aws-sdk": "*", 10 | "aws-iot-device-sdk": "*", 11 | "moment": "*", 12 | "randomstring": "*", 13 | "shortid": "*", 14 | "underscore": "*" 15 | }, 16 | "devDependencies": {}, 17 | "scripts": { 18 | "prestart": "npm install", 19 | "start": "node ./", 20 | "pretest": "npm install", 21 | "test": "karma start karma.conf.js", 22 | "test-single-run": "karma start karma.conf.js --single-run" 23 | }, 24 | "bundledDependencies": [] 25 | } 26 | -------------------------------------------------------------------------------- /source/services/jitr/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vhr-vehicle-jitr", 3 | "description": "A Lambda function for the vehicle just-in-time-registration microservice", 4 | "main": "index.js", 5 | "author": { 6 | "name": "aws-solutions-builder" 7 | }, 8 | "version": "0.0.1", 9 | "private": "true", 10 | "dependencies": { 11 | "aws-sdk": "*" 12 | }, 13 | "devDependencies": { 14 | "chai": "*", 15 | "sinon": "*", 16 | "sinon-chai": "*", 17 | "mocha": "*", 18 | "aws-sdk-mock": "*", 19 | "npm-run-all": "*", 20 | "proxyquire": "*" 21 | }, 22 | "scripts": { 23 | "pretest": "npm install", 24 | "test": "mocha *.spec.js", 25 | "build-init": "rm -rf dist && rm -f archive.zip && mkdir dist", 26 | "build:copy": "cp index.js dist/", 27 | "build:install": "cp package.json dist/ && cd dist && npm install --production", 28 | "build": "npm-run-all -s build-init build:copy build:install", 29 | "zip": "cd dist && zip -rq vhr-vehicle-jitr.zip ." 30 | }, 31 | "bundledDependencies": [] 32 | } 33 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | AWS Connected Vehicle Solution 2 | 3 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except 5 | in compliance with the License. A copy of the License is located at http://www.apache.org/licenses/ 6 | or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, 7 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the 8 | specific language governing permissions and limitations under the License. 9 | 10 | ********************** 11 | THIRD PARTY COMPONENTS 12 | ********************** 13 | This software includes third party software subject to the following copyrights: 14 | 15 | AWS SDK under the Apache License Version 2.0 16 | Underscore.js under the Massachusetts Institute of Technology (MIT) license 17 | Moment.js under the Massachusetts Institute of Technology (MIT) license 18 | shortid under the Massachusetts Institute of Technology (MIT) license 19 | randomstring under the Massachusetts Institute of Technology (MIT) license 20 | 21 | The licenses for these third party components are included in LICENSE.txt 22 | -------------------------------------------------------------------------------- /source/resources/helper/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ui-framework-helper", 3 | "description": "UI Framework custom resource helper Lambda function", 4 | "main": "index.js", 5 | "author": { 6 | "name": "aws-solutions-builder" 7 | }, 8 | "version": "0.0.1", 9 | "private": "true", 10 | "dependencies": { 11 | "aws-sdk": "*", 12 | "moment": "*", 13 | "underscore": "*", 14 | "node-uuid": "*", 15 | "fast-csv": "*" 16 | }, 17 | "devDependencies": { 18 | "chai": "*", 19 | "sinon": "*", 20 | "sinon-chai": "*", 21 | "mocha": "*", 22 | "aws-sdk-mock": "*", 23 | "npm-run-all": "*" 24 | }, 25 | "scripts": { 26 | "pretest": "npm install", 27 | "test": "mocha lib/*.spec.js", 28 | "build-init": "rm -rf dist && rm -f archive.zip && mkdir dist && mkdir dist/lib", 29 | "build:copy": "cp index.js dist/ && cp -r lib/*.js dist/lib", 30 | "build:install": "cp package.json dist/ && cp *.csv dist/ && cd dist && npm install --production", 31 | "build": "npm-run-all -s build-init build:copy build:install", 32 | "zip": "cd dist && zip -rq cv-deployment-helper.zip ." 33 | }, 34 | "bundledDependencies": [ 35 | "moment", 36 | "underscore", 37 | "node-uuid", 38 | "fast-csv" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /source/services/driversafety/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vhr-dtc-service", 3 | "description": "A Lambda function for the vehicle health report diagnostic trouble code microservice", 4 | "main": "index.js", 5 | "author": { 6 | "name": "aws-solutions-builder" 7 | }, 8 | "version": "0.0.1", 9 | "private": "true", 10 | "dependencies": { 11 | "aws-sdk": "*", 12 | "moment": "*", 13 | "shortid": "*", 14 | "underscore": "*" 15 | }, 16 | "devDependencies": { 17 | "aws-sdk-mock": "*", 18 | "chai": "*", 19 | "mocha": "*", 20 | "npm-run-all": "*", 21 | "proxyquire": "*", 22 | "sinon": "*", 23 | "sinon-chai": "*" 24 | }, 25 | "scripts": { 26 | "pretest": "npm install", 27 | "test": "env DTC_TBL='dtc' mocha lib/*.spec.js", 28 | "build-init": "rm -rf dist && rm -f archive.zip && mkdir dist && mkdir dist/lib", 29 | "build:copy": "cp index.js dist/ && cp -r lib/*.js dist/lib", 30 | "build:install": "cp package.json dist/ && cd dist && npm install --production", 31 | "build": "npm-run-all -s build-init build:copy build:install", 32 | "zip": "cd dist && zip -rq vhr-driver-safety-service.zip ." 33 | }, 34 | "bundledDependencies": [ 35 | "moment", 36 | "shortid", 37 | "underscore" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /source/services/notification/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vhr-notification-service", 3 | "description": "A Lambda function for the vehicle health report notification microservice", 4 | "main": "index.js", 5 | "author": { 6 | "name": "aws-solutions-builder" 7 | }, 8 | "version": "0.0.1", 9 | "private": "true", 10 | "dependencies": { 11 | "aws-sdk": "*", 12 | "moment": "*", 13 | "shortid": "*", 14 | "underscore": "*" 15 | }, 16 | "devDependencies": { 17 | "aws-sdk-mock": "*", 18 | "chai": "*", 19 | "mocha": "*", 20 | "npm-run-all": "*", 21 | "proxyquire": "*", 22 | "sinon": "*", 23 | "sinon-chai": "*" 24 | }, 25 | "scripts": { 26 | "pretest": "npm install", 27 | "test": "env VEHICLE_OWNER_TBL='vehicle_tbl' USER_POOL_ID='userpool' mocha lib/*.spec.js", 28 | "build-init": "rm -rf dist && rm -f archive.zip && mkdir dist && mkdir dist/lib", 29 | "build:copy": "cp index.js dist/ && cp -r lib/*.js dist/lib", 30 | "build:install": "cp package.json dist/ && cd dist && npm install --production", 31 | "build": "npm-run-all -s build-init build:copy build:install", 32 | "zip": "cd dist && zip -rq vhr-notification-service.zip ." 33 | }, 34 | "bundledDependencies": [ 35 | "moment", 36 | "shortid", 37 | "underscore" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /source/services/vehicle/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vhr-vehicle-service", 3 | "description": "A Lambda function for the vehicle microservice", 4 | "main": "index.js", 5 | "author": { 6 | "name": "aws-solutions-builder" 7 | }, 8 | "version": "0.0.1", 9 | "private": "true", 10 | "dependencies": { 11 | "aws-sdk": "*", 12 | "moment": "*", 13 | "shortid": "*", 14 | "underscore": "*" 15 | }, 16 | "devDependencies": { 17 | "aws-sdk-mock": "*", 18 | "chai": "*", 19 | "mocha": "*", 20 | "npm-run-all": "*", 21 | "proxyquire": "*", 22 | "sinon": "*", 23 | "sinon-chai": "*" 24 | }, 25 | "scripts": { 26 | "pretest": "npm install", 27 | "test": "env VEHICLE_ANOMALY_TBL='tblanomaly' VEHICLE_OWNER_TBL='tblowner' HEALTH_REPORT_TBL='tblhealthreport' mocha lib/*.spec.js", 28 | "build-init": "rm -rf dist && rm -f archive.zip && mkdir dist && mkdir dist/lib", 29 | "build:copy": "cp index.js dist/ && cp -r lib/*.js dist/lib", 30 | "build:install": "cp package.json dist/ && cd dist && npm install --production", 31 | "build": "npm-run-all -s build-init build:copy build:install", 32 | "zip": "cd dist && zip -rq vhr-vehicle-service.zip ." 33 | }, 34 | "bundledDependencies": [ 35 | "moment", 36 | "shortid", 37 | "underscore" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /source/services/anomaly/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vhr-anomaly-service", 3 | "description": "A Lambda function for the vehicle anomaly microservice", 4 | "main": "index.js", 5 | "author": { 6 | "name": "aws-solutions-builder" 7 | }, 8 | "version": "0.0.1", 9 | "private": "true", 10 | "dependencies": { 11 | "aws-sdk": "*", 12 | "moment": "*", 13 | "randomstring": "*", 14 | "shortid": "*", 15 | "underscore": "*" 16 | }, 17 | "devDependencies": { 18 | "aws-sdk-mock": "*", 19 | "chai": "*", 20 | "mocha": "*", 21 | "npm-run-all": "*", 22 | "proxyquire": "*", 23 | "sinon": "*", 24 | "sinon-chai": "*" 25 | }, 26 | "scripts": { 27 | "pretest": "npm install", 28 | "test": "env VEHICLE_ANOMALY_TBL='anomalytable' NOTIFICATION_SERVICE='notifyservice' mocha lib/*.spec.js", 29 | "build-init": "rm -rf dist && rm -f archive.zip && mkdir dist && mkdir dist/lib", 30 | "build:copy": "cp index.js dist/ && cp -r lib/*.js dist/lib", 31 | "build:install": "cp package.json dist/ && cd dist && npm install --production", 32 | "build": "npm-run-all -s build-init build:copy build:install", 33 | "zip": "cd dist && zip -rq vhr-anomaly-service.zip ." 34 | }, 35 | "bundledDependencies": [ 36 | "moment", 37 | "shortid", 38 | "underscore" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /source/services/dtc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vhr-dtc-service", 3 | "description": "A Lambda function for the vehicle dtc microservice", 4 | "main": "index.js", 5 | "author": { 6 | "name": "aws-solutions-builder" 7 | }, 8 | "version": "0.0.1", 9 | "private": "true", 10 | "dependencies": { 11 | "aws-sdk": "*", 12 | "moment": "*", 13 | "randomstring": "*", 14 | "shortid": "*", 15 | "underscore": "*" 16 | }, 17 | "devDependencies": { 18 | "aws-sdk-mock": "*", 19 | "chai": "*", 20 | "mocha": "*", 21 | "npm-run-all": "*", 22 | "proxyquire": "*", 23 | "sinon": "*", 24 | "sinon-chai": "*" 25 | }, 26 | "scripts": { 27 | "pretest": "npm install", 28 | "test": "env VEHICLE_TRIP_TBL='triptable' DTC_TBL='dtctable' NOTIFICATION_SERVICE='notifyservice' mocha lib/*.spec.js", 29 | "build-init": "rm -rf dist && rm -f archive.zip && mkdir dist && mkdir dist/lib", 30 | "build:copy": "cp index.js dist/ && cp -r lib/*.js dist/lib", 31 | "build:install": "cp package.json dist/ && cd dist && npm install --production", 32 | "build": "npm-run-all -s build-init build:copy build:install", 33 | "zip": "cd dist && zip -rq vhr-dtc-service.zip ." 34 | }, 35 | "bundledDependencies": [ 36 | "moment", 37 | "shortid", 38 | "underscore" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /source/services/marketing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vhr-marketing-service", 3 | "description": "A Lambda function for the location-based marketing microservice", 4 | "main": "index.js", 5 | "author": { 6 | "name": "aws-solutions-builder" 7 | }, 8 | "version": "0.0.1", 9 | "private": "true", 10 | "dependencies": { 11 | "aws-sdk": "*", 12 | "geolib": "*", 13 | "moment": "*", 14 | "underscore": "*" 15 | }, 16 | "devDependencies": { 17 | "aws-sdk-mock": "*", 18 | "chai": "*", 19 | "mocha": "*", 20 | "npm-run-all": "*", 21 | "proxyquire": "*", 22 | "sinon": "*", 23 | "sinon-chai": "*" 24 | }, 25 | "scripts": { 26 | "pretest": "npm install", 27 | "test": "env MKT_TBL='AdTrackingTable' POI_TBL='MarketingPoiTable' NOTIFICATION_SERVICE='notifyservice' mocha lib/*.spec.js", 28 | "build-init": "rm -rf dist && rm -f archive.zip && mkdir dist && mkdir dist/lib", 29 | "build:copy": "cp index.js dist/ && cp -r lib/*.js dist/lib", 30 | "build:install": "cp package.json dist/ && cd dist && npm install --production", 31 | "build": "npm-run-all -s build-init build:copy build:install", 32 | "zip": "cd dist && zip -rq vhr-marketing-service.zip ." 33 | }, 34 | "bundledDependencies": [ 35 | "moment", 36 | "geolib", 37 | "underscore" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /source/resources/helper/marketing-pois.csv: -------------------------------------------------------------------------------- 1 | va_rst_5,"11900 Market St, Reston, VA 20190",Reston,38.958439,-77.357138,Happy hour every weekday from 4-7pm. $2 off drinks and food,Dave's,500,VA 2 | va_rst_4,"12200 Sunset Hills Rd, Reston, VA 20190",Reston,38.954541,-77.366502,Show this message for free cornbread w/ purchase of any meal,Chris' Famous BBQ,500,VA 3 | va_rst_3,"770 Elden St, Herndon, VA 20170",Herndon,38.969389,-77.386678,Now serving breakfast!,Sean's Place,500,VA 4 | va_rst_2,"1200 Elden St, Herndon, VA 20170",Herndon,38.967435,-77.396295,Open Mon-Sun 11am-10pm. Check out our menu:,Herndon Tacos,500,VA 5 | va_rst_1,"14000 Parcher Ave, Herndon, VA 20170",Herndon,38.95934,-77.403683,Book your holiday party and get a $50 gift card:,The Bar,500,VA 6 | va_ret_3,"2500 McNair Farms Dr, Herndon, VA 20171",Herndon,38.94567,-77.408112,Free oil change this month,Herndon Car Repair,500,VA 7 | va_ret_2,"1700 Reston Pkwy, Reston, VA 20194",Reston,38.968398,-77.354168,Huge discounts on last season's items:,Reston Home Store,500,VA 8 | va_ret_1,"400 Elden St, Herndon, VA 20170",Herndon,38.96679,-77.376669,Find over $300 in savings with this week's deals:,Herndon Grocery,500,VA 9 | va_rec_1,"11800 Sunrise Valley Dr, Reston, VA 20191",Reston,38.943114,-77.352458,Don't forget to register for the the town 5k this weekend!,Reston Town Park,500,VA 10 | va_edu_1,"700 Dranesville Rd, Herndon, VA 20170",Herndon,38.97674,-77.377427,"Parents, don't forget, no school this Friday. Enjoy your long weekend!",Town High School,500,VA 11 | ,,,,,,,, -------------------------------------------------------------------------------- /source/resources/helper/obd-trouble-codes.csv: -------------------------------------------------------------------------------- 1 | "P0100","Mass or Volume Air Flow Circuit Malfunction" 2 | "P0101","Mass or Volume Air Flow Circuit Range/Performance Problem" 3 | "P0102","Mass or Volume Air Flow Circuit Low Input" 4 | "P0103","Mass or Volume Air Flow Circuit High Input" 5 | "P0104","Mass or Volume Air Flow Circuit Intermittent" 6 | "P0105","Manifold Absolute Pressure/Barometric Pressure Circuit Malfunction" 7 | "P0106","Manifold Absolute Pressure/Barometric Pressure Circuit Range/Performance Problem" 8 | "P0107","Manifold Absolute Pressure/Barometric Pressure Circuit Low Input" 9 | "P0108","Manifold Absolute Pressure/Barometric Pressure Circuit High Input" 10 | "P0109","Manifold Absolute Pressure/Barometric Pressure Circuit Intermittent" 11 | "P0110","IAT Circuit Malfunction" 12 | "P0111","Intake Air Temperature Circuit Range/Performance Problem" 13 | "P0112","Intake Air Temperature Circuit Low Input" 14 | "P0113","Intake Air Temperature Circuit High Input" 15 | "P0114","Intake Air Temperature Circuit Intermittent" 16 | "P0115","Engine Coolant Temperature Circuit Malfunction" 17 | "P0116","Engine Coolant Temperature Circuit Range/Performance Problem" 18 | "P0117","Engine Coolant Temperature Circuit Low Input" 19 | "P0118","Engine Coolant Temperature Circuit High Input" 20 | "P0119","Engine Coolant Temperature Circuit Intermittent" 21 | "P0120","Throttle Position Sensor/Switch A Circuit Malfunction" 22 | "P0121","Throttle Position Sensor/Switch A Circuit Range/Performance Problem" 23 | "P0122","Throttle Position Sensor/Switch A Circuit Low Input" 24 | "P0123","Throttle Position Sensor/Switch A Circuit High Input" 25 | "P0124","Throttle Position Sensor/Switch A Circuit Intermittent" 26 | "P0125","Insufficient Coolant Temperature for Closed Loop Fuel Control;" 27 | "P0126","ECT Excessive Time to Closed Loop Fuel Control" 28 | "P0128","Insufficient Coolant Temperature for Stable Operation" 29 | "P0130","Coolant Thermostat Malfunction" 30 | -------------------------------------------------------------------------------- /source/services/marketing/lib/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let AWS = require('aws-sdk'); 21 | let advertisement = require('./marketing.js'); 22 | 23 | module.exports.respond = function(event, cb) { 24 | 25 | let _ad = new advertisement(); 26 | _ad.getPoints(event, function(err, data) { 27 | if (err) { 28 | return cb(err, null); 29 | } 30 | 31 | return cb(null, data); 32 | }); 33 | 34 | }; 35 | -------------------------------------------------------------------------------- /source/services/driversafety/lib/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let AWS = require('aws-sdk'); 21 | let DriverSafety = require('./driver-safety.js'); 22 | 23 | module.exports.respond = function(event, cb) { 24 | 25 | // get predication and store results 26 | let _driverSafety = new DriverSafety(); 27 | _driverSafety.getDriverScorePrediction(event, function(err, data) { 28 | if (err) { 29 | console.log(err); 30 | return cb(err, null); 31 | } 32 | 33 | return cb(null, data); 34 | }); 35 | 36 | }; 37 | -------------------------------------------------------------------------------- /source/services/notification/lib/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let AWS = require('aws-sdk'); 21 | let Notification = require('./notification.js'); 22 | 23 | module.exports.respond = function(event, cb) { 24 | 25 | // get predication and store results 26 | let _notification = new Notification(); 27 | _notification.sendNotiviationViaMqtt(event, function(err, mdata) { 28 | if (err) { 29 | console.log(err); 30 | } 31 | 32 | _notification.sendNotification(event, function(err, data) { 33 | if (err) { 34 | console.log(err); 35 | return cb(err, null); 36 | } 37 | 38 | return cb(null, data); 39 | }); 40 | 41 | }); 42 | 43 | }; 44 | -------------------------------------------------------------------------------- /source/services/dtc/lib/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let AWS = require('aws-sdk'); 21 | let Dtc = require('./dtc.js'); 22 | 23 | module.exports.respond = function(event, cb) { 24 | 25 | let _dtc = new Dtc(); 26 | let _message = {}; 27 | 28 | if (typeof event === 'object') { 29 | _message = event; 30 | } else { 31 | _message = JSON.parse(event); 32 | } 33 | 34 | if (event.action) { 35 | 36 | } else if (event.timestamp && event.value) { 37 | // identify message as dtc object to be created from IoT platform 38 | _dtc.createDtc(event, function(err, data) { 39 | if (err) { 40 | return cb(err, null); 41 | } 42 | 43 | return cb(null, data); 44 | }); 45 | } 46 | 47 | }; 48 | -------------------------------------------------------------------------------- /source/services/dtc/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | console.log('Loading function'); 21 | let lib = require('./lib'); 22 | 23 | exports.handler = function(event, context, callback) { 24 | // Load the message passed into the Lambda function into a JSON object 25 | var eventText = JSON.stringify(event, null, 2); 26 | 27 | // Log a message to the console, you can view this text in the Monitoring tab in the Lambda console 28 | // or in the CloudWatch Logs console 29 | console.log('Received event:', eventText); 30 | 31 | lib.respond(event, function(error, response) { 32 | if (error) { 33 | console.error(error); 34 | return callback(null, error); 35 | } else { 36 | return callback(null, response); 37 | } 38 | }); 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /source/services/anomaly/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | console.log('Loading function'); 21 | let lib = require('./lib'); 22 | 23 | exports.handler = function(event, context, callback) { 24 | // Load the message passed into the Lambda function into a JSON object 25 | var eventText = JSON.stringify(event, null, 2); 26 | 27 | // Log a message to the console, you can view this text in the Monitoring tab in the Lambda console 28 | // or in the CloudWatch Logs console 29 | console.log('Received event:', eventText); 30 | 31 | lib.respond(event, function(error, response) { 32 | if (error) { 33 | console.error(error); 34 | return callback(null, error); 35 | } else { 36 | return callback(null, response); 37 | } 38 | }); 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /source/services/vehicle/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | console.log('Loading function'); 21 | let lib = require('./lib'); 22 | 23 | exports.handler = function(event, context, callback) { 24 | // Load the message passed into the Lambda function into a JSON object 25 | var eventText = JSON.stringify(event, null, 2); 26 | 27 | // Log a message to the console, you can view this text in the Monitoring tab in the Lambda console 28 | // or in the CloudWatch Logs console 29 | console.log('Received event:', eventText); 30 | 31 | lib.respond(event, function(error, response) { 32 | if (error) { 33 | console.error(error); 34 | return callback(null, error); 35 | } else { 36 | return callback(null, response); 37 | } 38 | }); 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /source/services/driversafety/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | console.log('Loading function'); 21 | let lib = require('./lib'); 22 | 23 | exports.handler = function(event, context, callback) { 24 | // Load the message passed into the Lambda function into a JSON object 25 | var eventText = JSON.stringify(event, null, 2); 26 | 27 | // Log a message to the console, you can view this text in the Monitoring tab in the Lambda console 28 | // or in the CloudWatch Logs console 29 | console.log('Received event:', eventText); 30 | 31 | lib.respond(event, function(error, response) { 32 | if (error) { 33 | console.error(error); 34 | return callback(null, error); 35 | } else { 36 | return callback(null, response); 37 | } 38 | }); 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /source/services/marketing/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | console.log('Loading function'); 21 | let lib = require('./lib'); 22 | 23 | exports.handler = function(event, context, callback) { 24 | // Load the message passed into the Lambda function into a JSON object 25 | var eventText = JSON.stringify(event, null, 2); 26 | 27 | // Log a message to the console, you can view this text in the Monitoring tab in the Lambda console 28 | // or in the CloudWatch Logs console 29 | console.log('Received event:', eventText); 30 | 31 | lib.respond(event, function(error, response) { 32 | if (error) { 33 | console.error(error); 34 | return callback(null, error); 35 | } else { 36 | return callback(null, response); 37 | } 38 | }); 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /source/services/notification/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | console.log('Loading function'); 21 | let lib = require('./lib'); 22 | 23 | exports.handler = function(event, context, callback) { 24 | // Load the message passed into the Lambda function into a JSON object 25 | var eventText = JSON.stringify(event, null, 2); 26 | 27 | // Log a message to the console, you can view this text in the Monitoring tab in the Lambda console 28 | // or in the CloudWatch Logs console 29 | console.log('Received event:', eventText); 30 | 31 | lib.respond(event, function(error, response) { 32 | if (error) { 33 | console.error(error); 34 | return callback(null, error); 35 | } else { 36 | return callback(null, response); 37 | } 38 | }); 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /source/services/anomaly/lib/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let AWS = require('aws-sdk'); 21 | let Anomaly = require('./anomaly.js'); 22 | 23 | module.exports.respond = function(event, cb) { 24 | 25 | let _anomaly = new Anomaly(); 26 | let _message = {}; 27 | 28 | if (typeof event === 'object') { 29 | _message = event; 30 | } else { 31 | _message = JSON.parse(event); 32 | } 33 | 34 | if (event.action) { 35 | 36 | } else { 37 | let payload = new Buffer(event.Records[0].kinesis.data, 'base64').toString('ascii'); 38 | console.log('Decoded payload:', payload); 39 | let _record = JSON.parse(payload); 40 | // identify message as dtc object to be created from IoT platform 41 | _anomaly.createAnomaly(_record, function(err, data) { 42 | if (err) { 43 | return cb(err, null); 44 | } 45 | 46 | return cb(null, data); 47 | }); 48 | } 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /source/services/marketing/lib/marketing.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let assert = require('chai').assert; 4 | let expect = require('chai').expect; 5 | let path = require('path'); 6 | let AWS = require('aws-sdk-mock'); 7 | AWS.setSDK(path.resolve('./node_modules/aws-sdk')); 8 | 9 | let advertisement = require('./marketing.js'); 10 | 11 | describe('advertisement', function() { 12 | 13 | let payload = { 14 | timestamp: '2017-12-19 18:10:46.836000000', 15 | trip_id: '59a84da4-0c17-4f6c-9405-8187dc1af3e5', 16 | vin: 'SAMPLEVIN123', 17 | name: 'location', 18 | latitude: '-12.34567', 19 | longitude: '98.76543' 20 | }; 21 | 22 | let poiRecord = { 23 | city: 'Henderson', 24 | poi_id: 'nv_rec_2', 25 | radius: '500', 26 | longitude: '-115.024756', 27 | message: 'Closed for Winter. Save on 2018 season passes:', 28 | address: '900 Galleria Dr, Henderson, NV 89011', 29 | poi: 'Cowabunga Bay Las Vegas', 30 | latitude: '36.072018', 31 | state: 'NV' 32 | }; 33 | 34 | describe('#getPoints', function() { 35 | 36 | beforeEach(function() {}); 37 | 38 | afterEach(function() { 39 | AWS.restore('DynamoDB.DocumentClient'); 40 | }); 41 | 42 | it('should return a list of POI records when ddb scan successful', function(done) { 43 | 44 | AWS.mock('DynamoDB.DocumentClient', 'scan', function(params, callback) { 45 | callback(null, { 46 | Items: [poiRecord] 47 | }); 48 | }); 49 | 50 | let _ad = new advertisement(); 51 | _ad.getPoints(payload, function(err, data) { 52 | if (err) done(err); 53 | else{ 54 | expect(data).to.equal('completed geo eval'); 55 | done(); 56 | } 57 | }); 58 | }); 59 | 60 | it('should return an error when ddb scan not successful', function(done) { 61 | 62 | AWS.mock('DynamoDB.DocumentClient', 'scan', function(params, callback) { 63 | callback('error',null); 64 | }); 65 | 66 | let _ad = new advertisement(); 67 | _ad.getPoints(payload, function(err, data) { 68 | if (err) { 69 | expect(err).to.equal('error'); 70 | done(); 71 | } else{ 72 | done(); 73 | } 74 | }); 75 | }); 76 | }); 77 | }); 78 | -------------------------------------------------------------------------------- /source/data-loaders/dtc-generator/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | const fs = require('fs'); 21 | let csv = require('fast-csv'); 22 | let fileStream = fs.createReadStream('./obd-trouble-codes.csv'); 23 | let parser = csv(); 24 | let codes = []; 25 | let codes_info = []; 26 | 27 | fileStream 28 | .on('readable', function() { 29 | var data; 30 | while ((data = fileStream.read()) !== null) { 31 | parser.write(data); 32 | } 33 | }) 34 | .on('end', function() { 35 | parser.end(); 36 | }); 37 | 38 | parser 39 | .on('readable', function() { 40 | var data; 41 | while ((data = parser.read()) !== null) { 42 | console.log(data); 43 | codes_info.push({ 44 | code: data[0], 45 | description: data[1] 46 | }); 47 | codes.push(data[0]); 48 | } 49 | }) 50 | .on('end', function() { 51 | console.log('done'); 52 | fs.writeFile('./dtc-info.js', JSON.stringify(codes_info), function(err) { 53 | if (err) { 54 | return console.log(err); 55 | } 56 | 57 | console.log('The file was saved!'); 58 | }); 59 | 60 | fs.writeFile('./diagnostic-trouble-codes.js', JSON.stringify(codes), function(err) { 61 | if (err) { 62 | return console.log(err); 63 | } 64 | 65 | console.log('The file was saved!'); 66 | }); 67 | }); 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS Connected Vehicle Solution 2 | The AWS Connected Vehicle Solution is a reference implementation that provides a foundation for automotive product transformations for connected vehicle services, autonomous driving, electric powertrains, and shared mobility. 3 | 4 | ## Getting Started 5 | To get started with the AWS Connected Vehicle Solution, please review the solution documentation. https://aws.amazon.com/answers/iot/connected-vehicle-solution/ 6 | 7 | ## Building distributables for customization 8 | * Configure the bucket name of your target Amazon S3 distribution bucket 9 | ``` 10 | export BUCKET_PREFIX=my-bucket-name 11 | ``` 12 | 13 | * Clone the repository, then build the distibutables: 14 | ``` 15 | cd ./deployment \n 16 | chmod +x build-s3-dist.sh \n 17 | ./build-s3-dist.sh \n 18 | ``` 19 | 20 | * Deploy the distibutables to an Amazon S3 bucket in your account. _Note:_ you must have the AWS Command Line Interface installed. 21 | 22 | ``` 23 | cd ./deployment \n 24 | s3 cp ./dist s3://my-bucket-name/aws-cv-solution/latest --recursive --profile aws-cred-profile-name \n 25 | ``` 26 | 27 | * Get the link of the aws-connected-vehicle-solution.template uploaded to your Amazon S3 bucket. 28 | * Deploy the AWS Connected Vehicle Solution to your account by launching a new AWS CloudFormation stack using the link of the aws-connected-vehicle-solution.template. 29 | 30 | ## File Structure 31 | The AWS Connected Vehicle Solution project consists of microservices that facilitate the functional areas of the platform. These microservices are deployed to a serverless environment in AWS Lambda. 32 | 33 |
34 | |-source/ 35 | |-services/ 36 | |-helper/ [ AWS CloudFormation custom resource deployment helper ] 37 | |-services/ 38 | |-anomaly/ [ microservice for humanization and persistence of identified anomalies ] 39 | |-driversafety/ [ microservice to orchestrate the creation of driver scores ] 40 | |-dtc/ [ microservice to orchestrate the capture, humanization and persistence of diagnostic trouble codes ] 41 | |-jitr/ [ microservice to orchestrate registration and policy creation for just-in-time registration of devices ] 42 | |-notification/ [ microservice to send SMS and MQTT notifications for the solution ] 43 | |-vehicle/ [ microservice to provide proxy interface for the AWS Connected Vehicle Solution API ] 44 |45 | 46 | Each microservice follows the structure of: 47 | 48 |
49 | |-service-name/ 50 | |-lib/ 51 | |-[ service module libraries and unit tests ] 52 | |-index.js [ injection point for microservice ] 53 | |-package.json 54 |55 | 56 | *** 57 | 58 | Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 59 | 60 | Licensed under the Amazon Software License (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at 61 | 62 | http://aws.amazon.com/asl/ 63 | 64 | or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and limitations under the License. 65 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/awslabs/aws-limit-monitor/issues), or [recently closed](https://github.com/awslabs/aws-limit-monitor/issues?q=is%3Aissue+is%3Aclosed), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *master* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Code of Conduct 44 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 45 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 46 | opensource-codeofconduct@amazon.com with any additional questions or comments. 47 | 48 | 49 | ## Security issue notifications 50 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 51 | 52 | 53 | ## Licensing 54 | 55 | See the [LICENSE](https://github.com/awslabs/aws-limit-monitor/blob/master/LICENSE.txt) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 56 | 57 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. -------------------------------------------------------------------------------- /source/data-loaders/dtc-generator/loader.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | const fs = require('fs'); 21 | let csv = require('fast-csv'); 22 | let parser = csv(); 23 | let codes_info = []; 24 | let AWS = require('aws-sdk'); 25 | 26 | const dynamoConfig = { 27 | region: 'us-east-1' 28 | }; 29 | const ddbTable = process.env.DTC_TABLE; 30 | 31 | let fileStream = fs.createReadStream('./obd-trouble-codes.csv'); 32 | fileStream 33 | .on('readable', function() { 34 | var data; 35 | while ((data = fileStream.read()) !== null) { 36 | parser.write(data); 37 | } 38 | }) 39 | .on('end', function() { 40 | parser.end(); 41 | }); 42 | 43 | parser 44 | .on('readable', function() { 45 | var data; 46 | while ((data = parser.read()) !== null) { 47 | console.log(data); 48 | codes_info.push({ 49 | dtc: data[0], 50 | description: data[1], 51 | steps: [] 52 | }); 53 | } 54 | }) 55 | .on('end', function() { 56 | console.log('done'); 57 | loadCodes(codes_info, 0, function(err, data) { 58 | if (err) { 59 | console.log(err); 60 | } else { 61 | console.log(data); 62 | } 63 | }); 64 | }); 65 | 66 | var loadCodes = function(items, index, cb) { 67 | if (index < items.length) { 68 | let params = { 69 | TableName: ddbTable, 70 | Item: items[index] 71 | }; 72 | 73 | let docClient = new AWS.DynamoDB.DocumentClient(dynamoConfig); 74 | docClient.put(params, function(err, data) { 75 | if (err) { 76 | console.log(err); 77 | } else { 78 | console.log(['Added DTC', params.Item.dtc].join(': ')); 79 | } 80 | 81 | index++; 82 | setTimeout(loadCodes, 100, items, index, cb); 83 | }); 84 | } else { 85 | return cb(null, 'All codes processed..'); 86 | } 87 | 88 | }; 89 | -------------------------------------------------------------------------------- /source/resources/helper/lib/metrics-helper.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let moment = require('moment'); 21 | let https = require('https'); 22 | 23 | /** 24 | * Helper function to interact with dynamodb for data lake cfn custom resource. 25 | * 26 | * @class metricsHelper 27 | */ 28 | let metricsHelper = (function() { 29 | 30 | /** 31 | * @class metricsHelper 32 | * @constructor 33 | */ 34 | let metricsHelper = function() {}; 35 | 36 | /** 37 | * Sends opt-in, anonymous metric. 38 | * @param {json} metric - metric to send to opt-in, anonymous collection. 39 | * @param {sendAnonymousMetric~requestCallback} cb - The callback that handles the response. 40 | */ 41 | metricsHelper.prototype.sendAnonymousMetric = function(metric, cb) { 42 | 43 | let _options = { 44 | hostname: 'metrics.awssolutionsbuilder.com', 45 | port: 443, 46 | path: '/generic', 47 | method: 'POST', 48 | headers: { 49 | 'Content-Type': 'application/json' 50 | } 51 | }; 52 | 53 | let request = https.request(_options, function(response) { 54 | // data is streamed in chunks from the server 55 | // so we have to handle the "data" event 56 | let buffer; 57 | let data; 58 | let route; 59 | 60 | response.on('data', function(chunk) { 61 | buffer += chunk; 62 | }); 63 | 64 | response.on('end', function(err) { 65 | data = buffer; 66 | cb(null, data); 67 | }); 68 | }); 69 | 70 | if (metric) { 71 | request.write(JSON.stringify(metric)); 72 | } 73 | 74 | request.end(); 75 | 76 | request.on('error', (e) => { 77 | console.error(e); 78 | cb(['Error occurred when sending metric request.', JSON.stringify(_payload)].join(' '), null); 79 | }); 80 | }; 81 | 82 | return metricsHelper; 83 | 84 | })(); 85 | 86 | module.exports = metricsHelper; 87 | -------------------------------------------------------------------------------- /source/resources/helper/lib/iot-helper.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let moment = require('moment'); 21 | let AWS = require('aws-sdk'); 22 | 23 | /** 24 | * Helper function to interact with AWS IoT for cfn custom resource. 25 | * 26 | * @class iotHelper 27 | */ 28 | let iotHelper = (function() { 29 | 30 | /** 31 | * @class iotHelper 32 | * @constructor 33 | */ 34 | let iotHelper = function() {}; 35 | 36 | /** 37 | * Creates an IoT topic rule. Stop gap for missing dynamoDBv2 in CFN. 38 | * @param {string} settings - Settings for creation of the IoT topic rule. 39 | * @param {createTopicRule~requestCallback} cb - The callback that handles the response. 40 | */ 41 | iotHelper.prototype.createTopicRule = function(settings, cb) { 42 | 43 | var params = { 44 | ruleName: settings.name, 45 | topicRulePayload: { 46 | actions: settings.actions, 47 | sql: settings.sql, 48 | description: settings.description, 49 | ruleDisabled: false 50 | } 51 | }; 52 | 53 | var iot = new AWS.Iot(); 54 | iot.createTopicRule(params, function(err, data) { 55 | if (err) { 56 | return cb(err, null); 57 | } 58 | 59 | return cb(null, data); 60 | 61 | }); 62 | }; 63 | 64 | /** 65 | * Deletes an IoT topic rule. Stop gap for missing dynamoDBv2 in CFN. 66 | * @param {string} settings - Settings for deletion of the IoT topic rule. 67 | * @param {deleteTopicRule~requestCallback} cb - The callback that handles the response. 68 | */ 69 | iotHelper.prototype.deleteTopicRule = function(settings, cb) { 70 | 71 | var params = { 72 | ruleName: settings.name 73 | }; 74 | 75 | var iot = new AWS.Iot(); 76 | iot.deleteTopicRule(params, function(err, data) { 77 | if (err) { 78 | console.log(err); 79 | } 80 | 81 | return cb(null, data); 82 | 83 | }); 84 | }; 85 | 86 | return iotHelper; 87 | 88 | })(); 89 | 90 | module.exports = iotHelper; 91 | -------------------------------------------------------------------------------- /source/services/driversafety/lib/driver-safety.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let assert = require('chai').assert; 4 | let expect = require('chai').expect; 5 | let path = require('path'); 6 | let AWS = require('aws-sdk-mock'); 7 | AWS.setSDK(path.resolve('./node_modules/aws-sdk')); 8 | 9 | let DriverSafety = require('./driver-safety.js'); 10 | 11 | describe('driversafety', function() { 12 | 13 | describe('#updateVehicleTrip', function() { 14 | 15 | let payload = { 16 | vin: 'SAMPLEVIN123', 17 | trip_id: 'TRIPID123' 18 | }; 19 | 20 | beforeEach(function() {}); 21 | 22 | afterEach(function() { 23 | AWS.restore('DynamoDB.DocumentClient'); 24 | }); 25 | 26 | it('should return success when ddb update is successful', function(done) { 27 | 28 | AWS.mock('DynamoDB.DocumentClient', 'put', function(params, callback) { 29 | callback(null, { 30 | result: 'success' 31 | }); 32 | }); 33 | 34 | let _driverSafety = new DriverSafety(); 35 | _driverSafety.updateVehicleTrip(payload, function(err, data) { 36 | if (err) done(err); 37 | else { 38 | assert.equal(data.result, 'success'); 39 | done(); 40 | } 41 | }); 42 | }); 43 | 44 | it('should return error information when ddb update fails', function(done) { 45 | 46 | AWS.mock('DynamoDB.DocumentClient', 'put', function(params, callback) { 47 | callback('error', null); 48 | }); 49 | 50 | let _driverSafety = new DriverSafety(); 51 | _driverSafety.updateVehicleTrip(payload, function(err, data) { 52 | if (err) { 53 | expect(err).to.equal('error'); 54 | done(); 55 | } else { 56 | done('invalid failure for negative test'); 57 | } 58 | }); 59 | 60 | }); 61 | }); 62 | 63 | describe('#getDriverScorePrediction', function() { 64 | 65 | let payload = { 66 | vin: 'SAMPLEVIN123', 67 | trip_id: 'TRIPID123' 68 | }; 69 | 70 | beforeEach(function() {}); 71 | 72 | afterEach(function() { 73 | AWS.restore('DynamoDB.DocumentClient'); 74 | }); 75 | 76 | it('should return success when driver prediction and update are successful', function(done) { 77 | 78 | AWS.mock('DynamoDB.DocumentClient', 'put', function(params, callback) { 79 | callback(null, { 80 | result: 'success' 81 | }); 82 | }); 83 | 84 | let _driverSafety = new DriverSafety(); 85 | _driverSafety.updateVehicleTrip(payload, function(err, data) { 86 | if (err) done(err); 87 | else { 88 | assert.equal(data.result, 'success'); 89 | done(); 90 | } 91 | }); 92 | }); 93 | 94 | it('should return error information when driver prediction or update fails', function(done) { 95 | 96 | AWS.mock('DynamoDB.DocumentClient', 'put', function(params, callback) { 97 | callback('error', null); 98 | }); 99 | 100 | let _driverSafety = new DriverSafety(); 101 | _driverSafety.updateVehicleTrip(payload, function(err, data) { 102 | if (err) { 103 | expect(err).to.equal('error'); 104 | done(); 105 | } else { 106 | done('invalid failure for negative test'); 107 | } 108 | }); 109 | 110 | }); 111 | }); 112 | 113 | }); 114 | -------------------------------------------------------------------------------- /source/services/vehicle/lib/vehicle.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let assert = require('chai').assert; 4 | let expect = require('chai').expect; 5 | let path = require('path'); 6 | let AWS = require('aws-sdk-mock'); 7 | AWS.setSDK(path.resolve('./node_modules/aws-sdk')); 8 | 9 | let Vehicle = require('./vehicle.js'); 10 | 11 | describe('vehicle', function() { 12 | 13 | describe('#listVehicles', function() { 14 | 15 | let _test_vehicle = { 16 | owner: 'user_test_com', 17 | vin: 'SAMPLEVIN123', 18 | nickname: 'Test Vehicle', 19 | odometer: 123 20 | }; 21 | 22 | let _ticket = { 23 | 'cognito:username': 'user_test_com' 24 | }; 25 | 26 | beforeEach(function() {}); 27 | 28 | afterEach(function() { 29 | AWS.restore('DynamoDB.DocumentClient'); 30 | }); 31 | 32 | it('should return list of vehicles when ddb query is successful', function(done) { 33 | 34 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 35 | callback(null, { 36 | Items: [_test_vehicle] 37 | }); 38 | }); 39 | 40 | let _vehicle = new Vehicle(); 41 | _vehicle.listVehicles(_ticket, function(err, data) { 42 | if (err) done(err); 43 | else { 44 | assert.equal(data.Items.length, 1); 45 | done(); 46 | } 47 | }); 48 | }); 49 | 50 | it('should return error information when ddb query fails', function(done) { 51 | 52 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 53 | callback('error', null); 54 | }); 55 | 56 | let _vehicle = new Vehicle(); 57 | _vehicle.listVehicles(_ticket, function(err, data) { 58 | if (err) { 59 | expect(err).to.equal('error'); 60 | done(); 61 | } else { 62 | done('invalid failure for negative test'); 63 | } 64 | }); 65 | 66 | }); 67 | }); 68 | 69 | describe('#getVehicle', function() { 70 | 71 | let _test_vehicle = { 72 | owner: 'user_test_com', 73 | vin: 'SAMPLEVIN123', 74 | nickname: 'Test Vehicle', 75 | odometer: 123 76 | }; 77 | 78 | let _ticket = { 79 | 'cognito:username': 'user_test_com' 80 | }; 81 | 82 | beforeEach(function() {}); 83 | 84 | afterEach(function() { 85 | AWS.restore('DynamoDB.DocumentClient'); 86 | }); 87 | 88 | it('should return a vehicle when ddb get is successful', function(done) { 89 | 90 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 91 | callback(null, { 92 | Item: _test_vehicle 93 | }); 94 | }); 95 | 96 | let _vehicle = new Vehicle(); 97 | _vehicle.getVehicle(_ticket, _test_vehicle.vin, function(err, data) { 98 | if (err) done(err); 99 | else { 100 | assert.equal(data, _test_vehicle); 101 | done(); 102 | } 103 | }); 104 | }); 105 | 106 | it('should return error information when ddb get fails', function(done) { 107 | 108 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 109 | callback('error', null); 110 | }); 111 | 112 | let _vehicle = new Vehicle(); 113 | _vehicle.getVehicle(_ticket, _test_vehicle.vin, function(err, data) { 114 | if (err) { 115 | expect(err).to.equal('error'); 116 | done(); 117 | } else { 118 | done('invalid failure for negative test'); 119 | } 120 | }); 121 | 122 | }); 123 | }); 124 | 125 | }); 126 | -------------------------------------------------------------------------------- /source/services/vehicle/lib/vehicle.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let shortid = require('shortid'); 21 | let moment = require('moment'); 22 | let _ = require('underscore'); 23 | let AWS = require('aws-sdk'); 24 | 25 | let creds = new AWS.EnvironmentCredentials('AWS'); // Lambda provided credentials 26 | const dynamoConfig = { 27 | credentials: creds, 28 | region: process.env.AWS_REGION 29 | }; 30 | const ddbTable = process.env.VEHICLE_OWNER_TBL; 31 | 32 | /** 33 | * Performs operations for vehicle management actions interfacing primiarly with 34 | * Amazon DynamoDB table. 35 | * 36 | * @class vehicle 37 | */ 38 | let vehicle = (function() { 39 | 40 | /** 41 | * @class vehicle 42 | * @constructor 43 | */ 44 | let vehicle = function() {}; 45 | 46 | /** 47 | * Retrieves a user's vehicles. 48 | * @param {JSON} ticket - authentication ticket 49 | * @param {listVehicles~callback} cb - The callback that handles the response. 50 | */ 51 | vehicle.prototype.listVehicles = function(ticket, cb) { 52 | var params = { 53 | TableName: ddbTable, 54 | KeyConditionExpression: 'owner_id = :uid', 55 | ExpressionAttributeValues: { 56 | ':uid': ticket['cognito:username'] 57 | } 58 | }; 59 | 60 | let docClient = new AWS.DynamoDB.DocumentClient(dynamoConfig); 61 | docClient.query(params, function(err, data) { 62 | if (err) { 63 | console.log(err); 64 | return cb(err, null); 65 | } 66 | 67 | return cb(null, data); 68 | }); 69 | 70 | }; 71 | 72 | /** 73 | * Registers a vehicle to and owner. 74 | * @param {JSON} ticket - authentication ticket 75 | * @param {JSON} vehicle - vehicle object 76 | * @param {createVehicle~callback} cb - The callback that handles the response. 77 | */ 78 | vehicle.prototype.createVehicle = function(ticket, vehicle, cb) { 79 | 80 | vehicle.owner_id = ticket['cognito:username']; 81 | 82 | let params = { 83 | TableName: ddbTable, 84 | Item: vehicle 85 | }; 86 | 87 | let docClient = new AWS.DynamoDB.DocumentClient(dynamoConfig); 88 | docClient.put(params, function(err, data) { 89 | if (err) { 90 | console.log(err); 91 | return cb(err, null); 92 | } 93 | 94 | return cb(null, vehicle); 95 | }); 96 | 97 | }; 98 | 99 | /** 100 | * Retrieves a user's registered vehicle. 101 | * @param {JSON} ticket - authentication ticket 102 | * @param {string} vin - vehicle identification number 103 | * @param {getVehicle~callback} cb - The callback that handles the response. 104 | */ 105 | vehicle.prototype.getVehicle = function(ticket, vin, cb) { 106 | 107 | let params = { 108 | TableName: ddbTable, 109 | Key: { 110 | owner_id: ticket['cognito:username'], 111 | vin: vin 112 | } 113 | }; 114 | 115 | let docClient = new AWS.DynamoDB.DocumentClient(dynamoConfig); 116 | docClient.get(params, function(err, data) { 117 | if (err) { 118 | console.log(err); 119 | return cb(err, null); 120 | } 121 | 122 | if (!_.isEmpty(data)) { 123 | return cb(null, data.Item); 124 | } else { 125 | return cb({ 126 | error: { 127 | message: 'The vehicle requested does not exist.' 128 | } 129 | }, null); 130 | } 131 | }); 132 | 133 | }; 134 | 135 | return vehicle; 136 | 137 | })(); 138 | 139 | module.exports = vehicle; 140 | -------------------------------------------------------------------------------- /source/services/vehicle/lib/anomaly.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let assert = require('chai').assert; 4 | let expect = require('chai').expect; 5 | let path = require('path'); 6 | let AWS = require('aws-sdk-mock'); 7 | AWS.setSDK(path.resolve('./node_modules/aws-sdk')); 8 | 9 | let Anomaly = require('./anomaly.js'); 10 | 11 | describe('anomaly', function() { 12 | 13 | describe('#listDtcByVehicle', function() { 14 | 15 | let _test_vehicle = { 16 | owner: 'user_test_com', 17 | vin: 'SAMPLEVIN123', 18 | nickname: 'Test Vehicle', 19 | odometer: 123 20 | }; 21 | 22 | let _test_anomaly = { 23 | acknowledged: false, 24 | anomaly_id: 'TEST123', 25 | vin: 'SAMPLEVIN123' 26 | }; 27 | 28 | let _ticket = { 29 | 'cognito:username': 'user_test_com' 30 | }; 31 | 32 | beforeEach(function() {}); 33 | 34 | afterEach(function() { 35 | AWS.restore('DynamoDB.DocumentClient'); 36 | }); 37 | 38 | it('should return list of dtc records when ddb query is successful', function(done) { 39 | 40 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 41 | callback(null, { 42 | Item: _test_vehicle 43 | }); 44 | }); 45 | 46 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 47 | callback(null, { 48 | Items: [_test_anomaly] 49 | }); 50 | }); 51 | 52 | let _anomaly = new Anomaly(); 53 | _anomaly.listAnomaliesByVehicle(_ticket, _test_vehicle.vin, function(err, data) { 54 | if (err) done(err); 55 | else { 56 | assert.equal(data.Items.length, 1); 57 | done(); 58 | } 59 | }); 60 | }); 61 | 62 | it('should return error information when ddb query fails', function(done) { 63 | 64 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 65 | callback(null, { 66 | Item: _test_vehicle 67 | }); 68 | }); 69 | 70 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 71 | callback('error', null); 72 | }); 73 | 74 | let _anomaly = new Anomaly(); 75 | _anomaly.listAnomaliesByVehicle(_ticket, _test_vehicle.vin, function(err, data) { 76 | if (err) { 77 | expect(err).to.equal('error'); 78 | done(); 79 | } else { 80 | done('invalid failure for negative test'); 81 | } 82 | }); 83 | 84 | }); 85 | }); 86 | 87 | describe('#getVehicleAnomaly', function() { 88 | 89 | let _test_vehicle = { 90 | owner: 'user_test_com', 91 | vin: 'SAMPLEVIN123', 92 | nickname: 'Test Vehicle', 93 | odometer: 123 94 | }; 95 | 96 | let _test_anomaly = { 97 | acknowledged: false, 98 | anomaly_id: 'TEST123', 99 | vin: 'SAMPLEVIN123' 100 | }; 101 | 102 | let _ticket = { 103 | 'cognito:username': 'user_test_com' 104 | }; 105 | 106 | beforeEach(function() {}); 107 | 108 | afterEach(function() { 109 | AWS.restore('DynamoDB.DocumentClient'); 110 | }); 111 | 112 | it('should return a anomaly when ddb get is successful', function(done) { 113 | 114 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 115 | if (params.TableName === 'tblowner') { 116 | callback(null, { 117 | Item: _test_vehicle 118 | }); 119 | } else { 120 | callback(null, { 121 | Item: _test_anomaly 122 | }); 123 | } 124 | }); 125 | 126 | let _anomaly = new Anomaly(); 127 | _anomaly.getVehicleAnomaly(_ticket, _test_vehicle.vin, _test_anomaly.anomaly_id, 128 | function(err, data) { 129 | if (err) done(err); 130 | else { 131 | assert.equal(data, _test_anomaly); 132 | done(); 133 | } 134 | }); 135 | }); 136 | 137 | it('should return error information when ddb get fails', function(done) { 138 | 139 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 140 | if (params.TableName === 'tblowner') { 141 | callback(null, { 142 | Item: _test_vehicle 143 | }); 144 | } else { 145 | callback('error', null); 146 | } 147 | }); 148 | 149 | let _anomaly = new Anomaly(); 150 | _anomaly.getVehicleAnomaly(_ticket, _test_vehicle.vin, _test_anomaly.anomaly_id, 151 | function(err, data) { 152 | 153 | if (err) { 154 | expect(err).to.equal('error'); 155 | done(); 156 | } else { 157 | done('invalid failure for negative test'); 158 | } 159 | }); 160 | }); 161 | }); 162 | 163 | }); 164 | -------------------------------------------------------------------------------- /source/services/vehicle/lib/healthreport.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let assert = require('chai').assert; 4 | let expect = require('chai').expect; 5 | let path = require('path'); 6 | let AWS = require('aws-sdk-mock'); 7 | AWS.setSDK(path.resolve('./node_modules/aws-sdk')); 8 | 9 | let HealthReport = require('./healthreport.js'); 10 | 11 | describe('healthreport', function() { 12 | 13 | describe('#listHealthReportsByVehicle', function() { 14 | 15 | let _test_vehicle = { 16 | owner: 'user_test_com', 17 | vin: 'SAMPLEVIN123', 18 | nickname: 'Test Vehicle', 19 | odometer: 123 20 | }; 21 | 22 | let _test_report = { 23 | report_id: '07dd5551-9e27-4fd5-813d-f5e009d773d0', 24 | vin: 'SAMPLEVIN123', 25 | owner_id: 'user_test_com' 26 | }; 27 | 28 | let _ticket = { 29 | 'cognito:username': 'user_test_com' 30 | }; 31 | 32 | beforeEach(function() {}); 33 | 34 | afterEach(function() { 35 | AWS.restore('DynamoDB.DocumentClient'); 36 | }); 37 | 38 | it('should return list of health report records when ddb query is successful', function(done) { 39 | 40 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 41 | callback(null, { 42 | Item: _test_vehicle 43 | }); 44 | }); 45 | 46 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 47 | callback(null, { 48 | Items: [_test_report] 49 | }); 50 | }); 51 | 52 | let _hr = new HealthReport(); 53 | _hr.listHealthReportsByVehicle(_ticket, _test_vehicle.vin, function(err, data) { 54 | if (err) done(err); 55 | else { 56 | assert.equal(data.Items.length, 1); 57 | done(); 58 | } 59 | }); 60 | }); 61 | 62 | it('should return error information when ddb query fails', function(done) { 63 | 64 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 65 | callback(null, { 66 | Item: _test_vehicle 67 | }); 68 | }); 69 | 70 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 71 | callback('error', null); 72 | }); 73 | 74 | let _hr = new HealthReport(); 75 | _hr.listHealthReportsByVehicle(_ticket, _test_vehicle.vin, function(err, data) { 76 | if (err) { 77 | expect(err).to.equal('error'); 78 | done(); 79 | } else { 80 | done('invalid failure for negative test'); 81 | } 82 | }); 83 | 84 | }); 85 | }); 86 | 87 | describe('#getVehicleHealthReport', function() { 88 | 89 | let _test_vehicle = { 90 | owner: 'user_test_com', 91 | vin: 'SAMPLEVIN123', 92 | nickname: 'Test Vehicle', 93 | odometer: 123 94 | }; 95 | 96 | let _test_report = { 97 | report_id: '07dd5551-9e27-4fd5-813d-f5e009d773d0', 98 | vin: 'SAMPLEVIN123', 99 | owner_id: 'user_test_com' 100 | }; 101 | 102 | let _ticket = { 103 | 'cognito:username': 'user_test_com' 104 | }; 105 | 106 | beforeEach(function() {}); 107 | 108 | afterEach(function() { 109 | AWS.restore('DynamoDB.DocumentClient'); 110 | }); 111 | 112 | it('should return a health report when ddb get is successful', function(done) { 113 | 114 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 115 | if (params.TableName === 'tblowner') { 116 | callback(null, { 117 | Item: _test_vehicle 118 | }); 119 | } else { 120 | callback(null, { 121 | Item: _test_report 122 | }); 123 | } 124 | }); 125 | 126 | let _hr = new HealthReport(); 127 | _hr.getVehicleHealthReport(_ticket, _test_vehicle.vin, _test_report.report_id, 128 | function(err, data) { 129 | if (err) done(err); 130 | else { 131 | assert.equal(data, _test_report); 132 | done(); 133 | } 134 | }); 135 | }); 136 | 137 | it('should return error information when ddb get fails', function(done) { 138 | 139 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 140 | if (params.TableName === 'tblowner') { 141 | callback(null, { 142 | Item: _test_vehicle 143 | }); 144 | } else { 145 | callback('error', null); 146 | } 147 | }); 148 | 149 | let _hr = new HealthReport(); 150 | _hr.getVehicleHealthReport(_ticket, _test_vehicle.vin, _test_report.report_id, 151 | function(err, data) { 152 | if (err) { 153 | expect(err).to.equal('error'); 154 | done(); 155 | } else { 156 | done('invalid failure for negative test'); 157 | } 158 | }); 159 | }); 160 | }); 161 | 162 | }); 163 | -------------------------------------------------------------------------------- /source/services/vehicle/lib/trip.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let assert = require('chai').assert; 4 | let expect = require('chai').expect; 5 | let path = require('path'); 6 | let AWS = require('aws-sdk-mock'); 7 | AWS.setSDK(path.resolve('./node_modules/aws-sdk')); 8 | 9 | let Trip = require('./trip.js'); 10 | 11 | describe('vehicle', function() { 12 | 13 | describe('#listDtcByVehicle', function() { 14 | 15 | let _test_vehicle = { 16 | owner: 'user_test_com', 17 | vin: 'SAMPLEVIN123', 18 | nickname: 'Test Vehicle', 19 | odometer: 123 20 | }; 21 | 22 | let _test_trip = { 23 | trip_id: '07dd5551-9e27-4fd5-813d-f5e009d773d0', 24 | vin: 'SAMPLEVIN123' 25 | }; 26 | 27 | let _ticket = { 28 | 'cognito:username': 'user_test_com' 29 | }; 30 | 31 | beforeEach(function() {}); 32 | 33 | afterEach(function() { 34 | AWS.restore('DynamoDB.DocumentClient'); 35 | }); 36 | 37 | it('should return list of trip records when ddb query is successful', function(done) { 38 | 39 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 40 | callback(null, { 41 | Item: _test_vehicle 42 | }); 43 | }); 44 | 45 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 46 | callback(null, { 47 | Items: [_test_trip] 48 | }); 49 | }); 50 | 51 | let _trip = new Trip(); 52 | _trip.listTripsByVehicle(_ticket, _test_vehicle.vin, function(err, data) { 53 | if (err) done(err); 54 | else { 55 | assert.equal(data.Items.length, 1); 56 | done(); 57 | } 58 | }); 59 | }); 60 | 61 | it('should return error information when ddb query fails', function(done) { 62 | 63 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 64 | callback(null, { 65 | Item: _test_vehicle 66 | }); 67 | }); 68 | 69 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 70 | callback('error', null); 71 | }); 72 | 73 | let _trip = new Trip(); 74 | _trip.listTripsByVehicle(_ticket, _test_vehicle.vin, function(err, data) { 75 | if (err) { 76 | expect(err).to.equal('error'); 77 | done(); 78 | } else { 79 | done('invalid failure for negative test'); 80 | } 81 | }); 82 | 83 | }); 84 | }); 85 | 86 | // describe('#getVehicleDtc', function() { 87 | // 88 | // let _test_vehicle = { 89 | // owner: 'user_test_com', 90 | // vin: 'SAMPLEVIN123', 91 | // nickname: 'Test Vehicle', 92 | // odometer: 123 93 | // }; 94 | // 95 | // let _test_dtc = { 96 | // acknowledged: false, 97 | // created_at: '2017-04-27T14:49:36Z', 98 | // udpated_at: '2017-04-27T14:49:36Z', 99 | // generated: '2017-04-27T14:49:34Z', 100 | // description: 'No description available.', 101 | // description: 'No description available.', 102 | // dtc: 'P0485', 103 | // dtc_id: 'TEST123', 104 | // vin: 'SAMPLEVIN123', 105 | // steps: [] 106 | // }; 107 | // 108 | // let _ticket = { 109 | // 'cognito:username': 'user_test_com' 110 | // }; 111 | // 112 | // beforeEach(function() {}); 113 | // 114 | // afterEach(function() { 115 | // AWS.restore('DynamoDB.DocumentClient'); 116 | // }); 117 | // 118 | // it('should return a vehicle when ddb get is successful', function(done) { 119 | // 120 | // AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 121 | // callback(null, { 122 | // Item: _test_vehicle 123 | // }); 124 | // }); 125 | // 126 | // AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 127 | // callback(null, { 128 | // Item: _test_vehicle 129 | // }); 130 | // }); 131 | // 132 | // let _vehicle = new Vehicle(); 133 | // _vehicle.getVehicle(_ticket, _test_vehicle.vin, function(err, data) { 134 | // if (err) done(err); 135 | // else { 136 | // assert.equal(data, _test_vehicle); 137 | // done(); 138 | // } 139 | // }); 140 | // }); 141 | // 142 | // it('should return error information when ddb get fails', function(done) { 143 | // 144 | // AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 145 | // callback('error', null); 146 | // }); 147 | // 148 | // let _vehicle = new Vehicle(); 149 | // _vehicle.getVehicle(_ticket, _test_vehicle.vin, function(err, data) { 150 | // if (err) { 151 | // expect(err).to.equal('error'); 152 | // done(); 153 | // } else { 154 | // done('invalid failure for negative test'); 155 | // } 156 | // }); 157 | // 158 | // }); 159 | // }); 160 | 161 | }); 162 | -------------------------------------------------------------------------------- /source/services/vehicle/lib/dtc.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let assert = require('chai').assert; 4 | let expect = require('chai').expect; 5 | let path = require('path'); 6 | let AWS = require('aws-sdk-mock'); 7 | AWS.setSDK(path.resolve('./node_modules/aws-sdk')); 8 | 9 | let Dtc = require('./dtc.js'); 10 | 11 | describe('vehicle', function() { 12 | 13 | describe('#listDtcByVehicle', function() { 14 | 15 | let _test_vehicle = { 16 | owner: 'user_test_com', 17 | vin: 'SAMPLEVIN123', 18 | nickname: 'Test Vehicle', 19 | odometer: 123 20 | }; 21 | 22 | let _test_dtc = { 23 | acknowledged: false, 24 | created_at: '2017-04-27T14:49:36Z', 25 | udpated_at: '2017-04-27T14:49:36Z', 26 | generated: '2017-04-27T14:49:34Z', 27 | description: 'No description available.', 28 | description: 'No description available.', 29 | dtc: 'P0485', 30 | dtc_id: 'TEST123', 31 | vin: 'SAMPLEVIN123', 32 | steps: [] 33 | }; 34 | 35 | let _ticket = { 36 | 'cognito:username': 'user_test_com' 37 | }; 38 | 39 | beforeEach(function() {}); 40 | 41 | afterEach(function() { 42 | AWS.restore('DynamoDB.DocumentClient'); 43 | }); 44 | 45 | it('should return list of dtc records when ddb query is successful', function(done) { 46 | 47 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 48 | callback(null, { 49 | Item: _test_vehicle 50 | }); 51 | }); 52 | 53 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 54 | callback(null, { 55 | Items: [_test_dtc] 56 | }); 57 | }); 58 | 59 | let _dtc = new Dtc(); 60 | _dtc.listDtcByVehicle(_ticket, _test_vehicle.vin, function(err, data) { 61 | if (err) done(err); 62 | else { 63 | assert.equal(data.Items.length, 1); 64 | done(); 65 | } 66 | }); 67 | }); 68 | 69 | it('should return error information when ddb query fails', function(done) { 70 | 71 | AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 72 | callback(null, { 73 | Item: _test_vehicle 74 | }); 75 | }); 76 | 77 | AWS.mock('DynamoDB.DocumentClient', 'query', function(params, callback) { 78 | callback('error', null); 79 | }); 80 | 81 | let _dtc = new Dtc(); 82 | _dtc.listDtcByVehicle(_ticket, _test_vehicle.vin, function(err, data) { 83 | if (err) { 84 | expect(err).to.equal('error'); 85 | done(); 86 | } else { 87 | done('invalid failure for negative test'); 88 | } 89 | }); 90 | 91 | }); 92 | }); 93 | 94 | // describe('#getVehicleDtc', function() { 95 | // 96 | // let _test_vehicle = { 97 | // owner: 'user_test_com', 98 | // vin: 'SAMPLEVIN123', 99 | // nickname: 'Test Vehicle', 100 | // odometer: 123 101 | // }; 102 | // 103 | // let _test_dtc = { 104 | // acknowledged: false, 105 | // created_at: '2017-04-27T14:49:36Z', 106 | // udpated_at: '2017-04-27T14:49:36Z', 107 | // generated: '2017-04-27T14:49:34Z', 108 | // description: 'No description available.', 109 | // description: 'No description available.', 110 | // dtc: 'P0485', 111 | // dtc_id: 'TEST123', 112 | // vin: 'SAMPLEVIN123', 113 | // steps: [] 114 | // }; 115 | // 116 | // let _ticket = { 117 | // 'cognito:username': 'user_test_com' 118 | // }; 119 | // 120 | // beforeEach(function() {}); 121 | // 122 | // afterEach(function() { 123 | // AWS.restore('DynamoDB.DocumentClient'); 124 | // }); 125 | // 126 | // it('should return a vehicle when ddb get is successful', function(done) { 127 | // 128 | // AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 129 | // callback(null, { 130 | // Item: _test_vehicle 131 | // }); 132 | // }); 133 | // 134 | // AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 135 | // callback(null, { 136 | // Item: _test_vehicle 137 | // }); 138 | // }); 139 | // 140 | // let _vehicle = new Vehicle(); 141 | // _vehicle.getVehicle(_ticket, _test_vehicle.vin, function(err, data) { 142 | // if (err) done(err); 143 | // else { 144 | // assert.equal(data, _test_vehicle); 145 | // done(); 146 | // } 147 | // }); 148 | // }); 149 | // 150 | // it('should return error information when ddb get fails', function(done) { 151 | // 152 | // AWS.mock('DynamoDB.DocumentClient', 'get', function(params, callback) { 153 | // callback('error', null); 154 | // }); 155 | // 156 | // let _vehicle = new Vehicle(); 157 | // _vehicle.getVehicle(_ticket, _test_vehicle.vin, function(err, data) { 158 | // if (err) { 159 | // expect(err).to.equal('error'); 160 | // done(); 161 | // } else { 162 | // done('invalid failure for negative test'); 163 | // } 164 | // }); 165 | // 166 | // }); 167 | // }); 168 | 169 | }); 170 | -------------------------------------------------------------------------------- /deployment/build-s3-dist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This assumes all of the OS-level configuration has been completed and git repo has already been cloned 4 | # 5 | # This script should be run from the repo's deployment directory 6 | # cd deployment 7 | # ./build-s3-dist.sh source-bucket-base-name trademarked-solution-name version-code 8 | # 9 | # Paramenters: 10 | # - source-bucket-base-name: Name for the S3 bucket location where the template will source the Lambda 11 | # code from. The template will append '-[region_name]' to this bucket name. 12 | # For example: ./build-s3-dist.sh solutions my-solution v1.0.0 13 | # The template will then expect the source code to be located in the solutions-[region_name] bucket 14 | # 15 | # - trademarked-solution-name: name of the solution for consistency 16 | # 17 | # - version-code: version of the package 18 | 19 | # Check to see if input has been provided: 20 | if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]; then 21 | echo "Please provide the base source bucket name, trademark approved solution name, version and template bucket name where the lambda code will eventually reside." 22 | echo "For example: ./build-s3-dist.sh solutions trademarked-solution-name v1.0.0" 23 | exit 1 24 | fi 25 | 26 | # Get reference for all important folders 27 | template_dir="$PWD" 28 | template_dist_dir="$template_dir/global-s3-assets" 29 | build_dist_dir="$template_dir/regional-s3-assets" 30 | source_dir="$template_dir/../source" 31 | 32 | echo "------------------------------------------------------------------------------" 33 | echo "[Init] Clean old dist folders" 34 | echo "------------------------------------------------------------------------------" 35 | echo "rm -rf $template_dist_dir" 36 | rm -rf $template_dist_dir 37 | echo "mkdir -p $template_dist_dir" 38 | mkdir -p $template_dist_dir 39 | echo "rm -rf $build_dist_dir" 40 | rm -rf $build_dist_dir 41 | echo "mkdir -p $build_dist_dir" 42 | mkdir -p $build_dist_dir 43 | 44 | echo "------------------------------------------------------------------------------" 45 | echo "[Packing] Templates" 46 | echo "------------------------------------------------------------------------------" 47 | echo "cp $template_dir/*.template $template_dist_dir" 48 | #cp -R $template_dir/*.template $template_dist_dir/ 49 | cp -R $template_dir/connected-vehicle-platform.yaml $template_dist_dir/aws-connected-vehicle-solution.template 50 | 51 | echo "Updating code source bucket in template with $1" 52 | replace="s/%%BUCKET_NAME%%/$1/g" 53 | sed -i '' -e $replace $template_dist_dir/*.template 54 | 55 | replace="s/%%SOLUTION_NAME%%/$2/g" 56 | sed -i '' -e $replace $template_dist_dir/*.template 57 | 58 | replace="s/%%VERSION%%/$3/g" 59 | sed -i '' -e $replace $template_dist_dir/*.template 60 | 61 | replace="s/%%TEMPLATE_BUCKET_NAME%%/$4/g" 62 | sed -i '' -e $replace $template_dist_dir/*.template 63 | 64 | echo "------------------------------------------------------------------------------" 65 | echo "[Rebuild] Services - anomaly" 66 | echo "------------------------------------------------------------------------------" 67 | 68 | cd $source_dir/services/anomaly 69 | npm install 70 | npm run build 71 | npm run zip 72 | cp dist/vhr-anomaly-service.zip $build_dist_dir/vhr-anomaly-service.zip 73 | 74 | echo "------------------------------------------------------------------------------" 75 | echo "[Rebuild] Services - driversafety" 76 | echo "------------------------------------------------------------------------------" 77 | 78 | cd $source_dir/services/driversafety 79 | npm install 80 | npm run build 81 | npm run zip 82 | cp dist/vhr-driver-safety-service.zip $build_dist_dir/vhr-driver-safety-service.zip 83 | 84 | echo "------------------------------------------------------------------------------" 85 | echo "[Rebuild] Services - marketing" 86 | echo "------------------------------------------------------------------------------" 87 | 88 | cd $source_dir/services/marketing 89 | npm install 90 | npm run build 91 | npm run zip 92 | cp dist/vhr-marketing-service.zip $build_dist_dir/vhr-marketing-service.zip 93 | 94 | echo "------------------------------------------------------------------------------" 95 | echo "[Rebuild] Services - dtc" 96 | echo "------------------------------------------------------------------------------" 97 | 98 | cd $source_dir/services/dtc 99 | npm install 100 | npm run build 101 | npm run zip 102 | cp dist/vhr-dtc-service.zip $build_dist_dir/vhr-dtc-service.zip 103 | 104 | echo "------------------------------------------------------------------------------" 105 | echo "[Rebuild] Services - notification" 106 | echo "------------------------------------------------------------------------------" 107 | 108 | cd $source_dir/services/notification 109 | npm install 110 | npm run build 111 | npm run zip 112 | cp dist/vhr-notification-service.zip $build_dist_dir/vhr-notification-service.zip 113 | 114 | echo "------------------------------------------------------------------------------" 115 | echo "[Rebuild] Services - vehicle" 116 | echo "------------------------------------------------------------------------------" 117 | 118 | cd $source_dir/services/vehicle 119 | npm install 120 | npm run build 121 | npm run zip 122 | cp dist/vhr-vehicle-service.zip $build_dist_dir/vhr-vehicle-service.zip 123 | 124 | echo "------------------------------------------------------------------------------" 125 | echo "[Rebuild] Services - jitr" 126 | echo "------------------------------------------------------------------------------" 127 | 128 | cd $source_dir/services/jitr 129 | npm install 130 | npm run build 131 | npm run zip 132 | cp dist/vhr-vehicle-jitr.zip $build_dist_dir/vhr-vehicle-jitr.zip 133 | 134 | echo "------------------------------------------------------------------------------" 135 | echo "[Rebuild] Resources - helper" 136 | echo "------------------------------------------------------------------------------" 137 | 138 | cd $source_dir/resources/helper 139 | npm install 140 | npm run build 141 | npm run zip 142 | cp dist/cv-deployment-helper.zip $build_dist_dir/cv-deployment-helper.zip 143 | -------------------------------------------------------------------------------- /source/services/jitr/index.js: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************************* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * 3 | * * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance * 5 | * with the License. A copy of the License is located at * 6 | * * 7 | * http://www.apache.org/licenses/LICENSE-2.0 * 8 | * * 9 | * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES * 10 | * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions * 11 | * and limitations under the License. * 12 | *********************************************************************************************************************/ 13 | 14 | /** 15 | * @author Solution Builders 16 | */ 17 | 18 | 'use strict'; 19 | 20 | /** 21 | This node.js Lambda function code creates and attaches an IoT policy to the 22 | just-in-time registered certificate. It also activates the certificate. The Lambda 23 | function is attached as a rule engine action to the registration topic 24 | Saws/events/certificates/registered/