Skip to content

kemp/blood-pressure-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blood Pressure Logger

Blood Pressure Logger is a simple serverless web application that allows a user to upload their blood pressure data and view their previously submitted data.

Features

  • Submit blood pressure data to DynamoDB
  • View blood pressure from DynamoDB
  • Warn the user when their blood pressure is abnormally high

Installation

Part 0. Prerequisite steps

  1. Download (or clone) the code
  2. Create an AWS account (we should remain within free tier)

Part 1. Create DynamoDB table

  1. From the AWS Management Console, find the service "DynamoDB"
  2. Create a new table:
    1. Table name: BloodPressureLogger
    2. Primary key: LogID as String
    3. Ensure that "Add sort key" is unchecked
    4. Ensure the "Use default settings" is checked

Part 2. Create lambda functions

  1. From the AWS Management Console, find the service "Lambda"
  2. Create a new Lambda function:
    1. Function name: GetBloodPressure
    2. Runtime: Node.js 12.x
    3. Execution role: "Create a new role with basic Lambda permissions"
  3. Add the function code:
    1. Below the function, choose to edit the code inline
    2. Copy the code from 'functions/getData.js' in this repository
    3. Paste it into the code editor, replacing the existing code
    4. If you used a different DynamoDB table name other than BloodPressureLogger from Part 1, replace the name you used for the variable "DYNAMODB_TABLE_NAME" in the function code
    5. Click "Save"
  4. Go to the "Permissions" tab of the function and select the autogenerated role name, which should look something like GetBloodPressure-role-[something]
  5. From the new tab, select "Add inline policy" from the "Permission policies" subheading:
    1. Use the visual editor
    2. Service: DynamoDB
    3. Actions: search for Scan or find it under the Read dropdown and select it
    4. Choose All resources
    5. Click Review policy
    6. Name: DynamoDBScanPolicy
    7. Click Create policy
  6. Return to the Lambda dashboard and create another Lambda function:
    1. Function name: LogBloodPressure
    2. Runtime: Node.js 12.x
    3. Execution role: "Create a new role with basic Lambda permissions"
  7. Add the function code:
    1. Below the function, choose to edit the code inline
    2. Copy the code from 'functions/logData.js' in this repository
    3. Paste it into the code editor, replacing the existing code
    4. If you used a different DynamoDB table name other than BloodPressureLogger from Part 1, replace the name you used for the variable "DYNAMODB_TABLE_NAME" in the function code
    5. Click "Save"
  8. Go to the "Permissions" tab of the function and select the autogenerated role name, which should look something like LogBloodPressure-role-[something]
  9. From the new tab, select "Add inline policy" from the "Permission policies" subheading:
    1. Use the visual editor
    2. Service: DynamoDB
    3. Actions: search for PutItem or find it under the Write dropdown and select it
    4. Resources: Choose All resources
    5. Click Review policy
    6. Name: DynamoDBPutItemPolicy
    7. Click Create policy

Part 3. API Gateway

  1. From the AWS Management Console, find the service "API Gateway"
  2. Create a new REST API:
    1. Type: REST
    2. Select New API
    3. API name: BloodPressureLogger
    4. Endpoint type: Edge optimized
  3. From the "Actions" dropdown, choose "Create Resource":
    1. Ensure that "Configure as proxy resource" is unchecked
    2. Resource name: Log
    3. Resource path: log
    4. Ensure that "Enable API Gateway CORS" is checked
    5. Click "Create Resource"
  4. With the new resource selected, choose "Create Method" from the "Actions" dropdown
    1. Select "GET" from the new dropdown below the resource and click the Check icon
    2. Configure the new method:
      1. Integration type: Lambda function
      2. Use Lambda Proxy integration: checked
      3. Lambda function: GetBloodPressure (or the name you chose from part 2)
      4. Click "Save" and allow permissions
  5. With the resource selected, choose "Create Method" from the "Actions" dropdown
    1. Select "POST" from the new dropdown below the resource and click the Check icon
    2. Configure the new method:
      1. Integration type: Lambda function
      2. Use Lambda Proxy integration: checked
      3. Lambda function: LogBloodPressure (or the name you chose from part 2)
      4. Click "Save"
  6. With the resource selected, choose "Deploy API" from the actions dropdown:
    1. Deployment stage: [New Stage]
    2. Stage name: prod
    3. Click "Create"
  7. From the "prod Stage Editor", click the down arrow next to "prod" to expand the options and click "GET"
  8. Find the Invoke URL and save it for later (it should be something like: https://[something].execute-api.[region].amazonaws.com/prod/log)

Part 4. Static assets

  1. From the AWS Management Console, find the service "S3"
  2. Create a new bucket:
    1. Name: blood-pressure-logger-[your-last-name] (if that already exists, append a number to the end)
    2. Ensure that "Block all public access" is unchecked
    3. Check "I acknowledge that the current settings might result in this bucket and the objects within becoming public."
    4. Click "Create bucket"
  3. From your code editor of choice (on your machine), open index.html from this repository
    1. Scroll down until you find "{{INVOKE_URL}}" and replace it with the URL found from the previous part
  4. From your code editor of choice (on your machine), open show.html from this repository
    1. Scroll down until you find "{{INVOKE_URL}}" and replace it with the URL found from the previous part
  5. Select the newly created bucket from the AWS console
  6. Select "Upload" and upload the modified files: index.html and show.html
  7. Select "Next"
  8. Under "Manage Public Permissions", choose "Grant public read access to this object(s)"
  9. Go to the "Properties" tab
  10. Select "Static website hosting"
  11. Choose "Use this bucket to host a website"
    1. Index document: index.html
    2. Copy the Endpoint URL shown
    3. Click "Save"
  12. Open the Endpoint URL shown from the previous step to see the Blood Pressure Logger in action
  13. Try it out!

Disclaimers

  • This should not be used in a production environment and is provided for informational purposes only
  • This comes with no warranty
  • I am not liable for any costs incurred on your AWS account as a result of following this tutorial