If you reading this you must have came from the first repository after building the electonics and cloud infrusture. If you not created the electronic step or cloud infrusture yet, please go back to the first repository and complete the steps leading up to this point.
This repository is built for the React serverlesss site we are going to host on AWS Amplify. Since React can run in a moblie/web browser it make it a perfect microframe to use. I will be making a improvment to website sytling and feature in the future. The sytling is very bare minminal because I not familar with front-end development and there already so much work with the backend. Please follow the instruction below to correctly link your smart doorlock.
We are going to build this portion of the diagram today, please follow the step below in squencal order.
Please click on any pictures/GIFs to enlarge them
-
Click for General Setup Instruction
- Make sure all the prerequisites are all met and installed
- Clone this repo
git clone https://github.com/KevyVo/Door_staticsite
- cd into the directory alarmsite
~/Door_staticsite/alarmsite
- Install all the packages
npm install
- Once all the steps are completed move onto amplify Setup
-
Click for React Setup Instruction
We are going to enter the right aws information for your cloud service that created in the first repo and change some user customication
- Please open your AWS console and navigate to AWS Iot Core
- The endpoint should be found here, please copy this since we will be using this shortly
- Please navigate to the App.js for React,
alarmsite/src/App.js
- Please change the endpoint and region here with endpoint and region
-
Amplify.addPluggable(new AWSIoTProvider({ aws_pubsub_region: 'us-west-2', aws_pubsub_endpoint: 'wss://a1w99or2wkkhk5-ats.iot.us-west-2.amazonaws.com/mqtt', }));
-
- Now change name to your name now, localed in display-name
-
<div className="App"> <ToggleSwitch id="Override" checked={ Override } onChange={ onOverrideChange } /> <label htmlFor="Override">Door Override</label> <div className="display-name">Hello, Kevin</div> <AmplifySignOut /> <Container className="p-4"> <Row className="p-3 justify-content-md-center"> <Col md="auto"> <Sensors name="userID" unit=""/> </Col> <Col md="auto"> <Sensors name="Timestamp" unit=""/> </Col> <Col md="auto"> <Sensors name="Door" unit=""/> </Col> <Col md="auto"> <Sensors name="Accuracy" unit=""/> </Col> <Col md="auto"> <Sensors name="Finger" unit=""/> </Col> </Row> </Container> </div>
-
- Now save the js file
- Now navigate to
alarmsite/src/components/sensorData.js
- We need to change template endpoint and region to your endpoint and region once again
-
aws_pubsub_region: 'us-west-2', aws_pubsub_endpoint: 'wss://a1w99or2wkkhk5-ats.iot.us-west-2.amazonaws.com/mqtt', }));
-
- Save the js file
- Once successful please move onto the Amplify instructions
-
Click for Amplify Setup Instruction
Please refer to this supporting documentation if any errors occurs
- Use the same AWS account we made for database in the first
- Install the Amplify CLI if you have not,
npm install -g @aws-amplify/cli
- Setup add new user,
amplify configure
- Create a new user when the window popup
- Please download the csv or keep the page with credtional page up
- Please fill out the prompts on the terminal like this
-
Enter the access key of the newly created user: ? accessKeyId: # YOUR_ACCESS_KEY_ID ? secretAccessKey: # YOUR_SECRET_ACCESS_KEY This would update/create the AWS Profile in your local machine ? Profile Name: # (default)
-
- Initialize Amplify
amplify init
- Please follow the screenshot below, unless you know what you are doing
- If everything was successful you can just move on to Authentication setup
-
Click for Authentication Setup Instruction
- Since we are going to use the console to config other setting in Cognitio, we only need very simple setup
- Please run
amplify add auth
to add authentication - Once successful please run
amplify push
, this push all the changes to the cloud - We can now test our Web app by running,
npm start
- Once the page has launch successful we can close that port/terminal and move onto cloud infrusture
-
Click for Cloud Architecture Instruction
- Navigate to the AWS Iot Core
- Now go to to Secure->Policies->Create
- Now fill out the form like this
- Now we need to start out local server,
npm start
- Once the site has loaded, please sign up. Your E-mail should be the same as your username.
- Please do throught the veriying your account with you e-mail
- Once the account is veried, please login using the credential you just create
- Now open up the the console log and you should have your Cognito Idenity Id log into the Console Log. This was possbile to the line we had in out App.js in our src folder.
Auth.currentCredentials().then(creds => console.log(creds));
- Copy the ID as we will need it in the next following steps
- Please refer to the guide on alternate method if you don`t use Linux or mac
- Run
sudo apt-get update
- Then run
sudo apt-get install awscli
- Finally insert the iotpolicy name you create along with the ID,
aws iot attach-principal-policy --policy-name 'myIoTPolicy' --principal '<YOUR_COGNITO_IDENTITY_ID>'
- Open the AWS Console and Navigate to CloudFormation
- Then look for the stack you just created. It should have 3 resources in it, which are AuthRole, UnauthRole and DepolymentBucket.
- Click on the authRole physical ID, this should take you IAM roles
- Now Click on attach policies
- We need to add two polices
- AWSIoTConfigAccess
- AWSIoTDataAccess
- Click Attach Policy
- Since we are the only one that want to have access the site, we need to not have sign up open to others. Please navigate to Cognitio on the AWS console.
- Please follow the instruction and gif I have link below:
- We now need to host our react site so you can access via the internet. Open the terminal and navigate to alarmsite root folder
cd Door_staticsite/alarmsite
- Please follow the gif and instruction I have attach below:
- If you don`t want to host on a custom domain(step 6) please return back to the first repo and move onto step 5(Smart Light).
-
Click for Custom Domain Instruction (OPTIONAL)
- Please navigate to Route 53 in the AWS Console
- Please follow the gif and instruction I have attach below:
- In the Register a domain, type a domain name you would like
- Choose a avalilble domain ending or research for a new domain
- add the domain to cart (WILL COST X Amount, this is only part of the project that will cost money)
- click continue
- Contact type: Person
- Privacy Protection: Enable
- Click continue
- Check over information, agree to the terms then click compelte order
- Now wait for the domain to be ready for to be use (about 15 mins)
- Please navigate to Amplify in the AWS Console
- Please follow the gif and instruction below
- Please return back to the first repo and move onto step 5(Smart Light).
- AWS Amplify - Used for static hosting
- AWS Cognitio - Used for User authenication and user management
- AWS IOT Core - Used to do MQTT and PUbSub, also will log into a NoSQL database (DynamoDB)
- AWS DynamoDB - Used to do store user, profile and entry data into NoSQL table
- AWS Route53 - Used to secure custom domains
- AWS S3 - Used to host and store serverless site
wfh-serverless-site (root)
├───alarmsite (React Folder)
│ ├───amplify
│ │ ├───.config
│ │ └───backend
│ │ ├───auth
│ │ │ └───alarmsite2beaa5f9
│ │ └───hosting
│ │ └───amplifyhosting
│ ├───public
│ └───src
│ └───components
├───gif
└───Pictures
I want to take the time to say thank you to these fellow authors of these documentions, without them this project would not be possible. These pieces are a great learning resource if you want to give them a read.
How to interact with AWS and push to DynamoDB