Code Monkey home page Code Monkey logo

ask-around-me's Introduction

Ask Around Me - Get your questions answered by local users

This example application shows how to build a serverless web application including features like authentication, geohashing and realtime messaging.

To learn more about how this application works, see the 3-part series on the AWS Compute Blog:

πŸ“Ί Watch the YouTube video series at https://serverlessland.com/learn/ask-around-me

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

.
β”œβ”€β”€ README.MD                   <-- This instructions file
β”œβ”€β”€ backend                     <-- Source code for the serverless backend
β”œβ”€β”€ frontend                    <-- Source code for the Vue.js frontend

Requirements

Auth0 configuration

  1. Sign up for an Auth0 account at https://auth0.com.
  2. Select Applications from the menu, then choose Create Application.
  3. Enter the name Ask Around Me and select Single Page Web Applications for application type. Choose Create.
  4. Select the Settings tab, and note the Domain and ClientID for installation of the application backend and frontend.
  5. Under Allowed Callback URLs, Allowed Logout URLs and Allowed Web Origins and Allowed Origins (CORS), enter http://localhost:8080. Choose Save Changes.
  6. Select APIS from the menu, then choose Create API.
  7. Enter the name Ask Around Me, and set the Identifier to https://auth0-jwt-authorizer. Choose Create.

Auth0 is now configured for you to use. The backend uses the domain value to validate the JWT token. The frontend uses the identifier (also known as the audience), together with the Client ID to validate authentication for this single application. For more information, see the Auth0 documentation.

Installation Instructions

  1. Create an AWS account if you do not already have one and login.

  2. Clone the repo onto your local development machine using git clone.

Installing the realtime stack

  1. From the command line, install the realtime messaging stack:
cd backend
sam deploy --guided --template-file realtime.yaml

During the prompts, enter askAroundMe-realtime for the Stack Name, enter your preferred Region, and accept the defaults for the remaining questions.

  1. Retrieve the IoT endpointAddress - note this for the frontend installation:
aws iot describe-endpoint --endpoint-type iot:Data-ATS
  1. Retrieve the Cognito Pool ID - note this for the frontend installation:
aws cognito-identity list-identity-pools --max-results 10

Installing the DynamoDB geohash library

  1. From the command line, setup the dynamodb-geo library and DynamoDB table:
cd setup
npm install
node ./setup.js <<REGION>>

Replace <<REGION>> with your preferred AWS Region (e.g. us-east-1)

This process takes up to 1 minute to complete.

  1. After this, retrieve the DynamoDB StreamArn value for the next part of the installation, using the following command:
aws dynamodbstreams list-streams --table-name aamQuestions

Installing the backend application

From the command line, deploy the SAM template. Note that your SAM version must be at least 0.48 - if you receive build errors, it is likely that your SAM CLI version is not up to date. Run:

cd .. 
sam build
sam deploy --guided

When prompted for parameters, enter:

  • Stack Name: askAroundMe-backend
  • AWS Region: your preferred AWS Region (e.g. us-east-1)
  • QuestionsTableName: leave as default
  • QuestionsTableStreamARN: enter the stream ARN you noted in the last section.
  • AnswersTableName: leave as default
  • IoTDataEndpoint: the IoT endpointAddress noted in the realtime stack installation.
  • Auth0issuer: this is the URL for the Auth0 account (the format is https://dev-abc12345.auth0.com/).
  • Accept all other defaults.

This takes several minutes to deploy. At the end of the deployment, note the APIendpoint value, as you need this in the frontend installation.

Installing the frontend application

The frontend code is saved in the frontend subdirectory.

  1. Before running, you need to set environment variables in the src\main.js file:
  • GoogleMapsKey: sign up for a Google Maps API key and enter the value here.
  • APIurl: this is the APIendpoint value from the last section.
  • PoolId: your Cognito pool ID from earlier.
  • Host: your IoT endpoint from earlier.
  • Region: your preferred AWS Region (e.g. us-east-1).
  1. Open the frontend\auth_config.json and enter the values from your Auth0 account:
  • domain: this is your account identifier, in the format dev-12345678.auth0.com.
  • clientId: a unique string identifying the client application.
  • audience: set to https://auth0-jwt-authorizer.
  1. Change directory into the frontend code, and run the NPM installation:
cd ../frontend
npm install
  1. After installation is complete, you can run the application locally:
npm run build

Next steps

The AWS Compute Blog series and video link at the top of this README file contains additional information about the application design and architecture.

If you have any questions, feel free to DM the author on Twitter or raise an issue in the GitHub repo.

==============================================

Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0

ask-around-me's People

Contributors

amazon-auto avatar dependabot[bot] avatar jbesw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ask-around-me's Issues

Idempotency Concern in ProcessAnswersStreamFunction

Description:

I would like to kindly bring attention to a potential issue with the ProcessAnswersStreamFunction, which is invoked when incoming star rating answers or geo answers enter the DynamoDB through either ProcessAnswerStarFunction or ProcessAnswerGeoFunction. In the star.updateQuestionsTable and geo.updateQuestionsTable methods, the program uses the Dynamo’s ADD UpdateExpression to change the absolute count of star rating answers or geo answers. However, this implementation is not idempotent. Suppose when the function is invoked, the star rating of a specific answer is increased by 1; if the function crashes and retries, the star rating will be increased again by 1. This is not desired, as it duplicates the user's action (starring the answer) at untimely retries.

Suggested Fix:

To address this issue, please consider adding a LastRequestId field to the record that logs the most recent lambda's request id, and use a ConditionExpression along with the original ADD UpdateExpression. Specifically, only if context.aws_request_id != item.LastRequestId, apply the star rating change and update the LastRequestId field. This approach should help ensure idempotency and improve the reliability of the ProcessAnswersStreamFunction since the request id is constant across retries.

Thank you for considering this issue. I hope my suggestion proves helpful in enhancing the reliability and idempotency of the ProcessAnswersStreamFunction. Please don't hesitate to reach out if you have any questions or concerns.

ERR_TOO_MANY_REDIRECTS

When I try viewing the production site, I get the following error:

image

I have tried using my local code that works and commited to CodeCommit and also using Github. Any ideas/suggestions?

access_denied

When I try running the application locally and click the log in button, the url in the browser has the following value:

http://localhost:8080/?error=access_denied&error_description=Service%20not%20found%3A%20https%3A%2F%2Fauth0-jwt-authorizer&state=Mm5Fdi1mVjNvdldwY1p0dGNNeU5tcDlPblJqOW14Mi1fNmVDV213YlljVA%3D%3D

=======================
Debug window has this info:

asyncToGenerator.js?1da1:6 Uncaught (in promise) {error: "access_denied", error_description: "Service not found: https://auth0-jwt-authorizer", state: "MU9sfkljVUlQVElVSmR6Q05KRzVQbjhDejBfYS1yamxnSjUyQ2gwYl80TQ=="}error: "access_denied"error_description: "Service not found: https://auth0-jwt-authorizer"state: "MU9sfkljVUlQVElVSmR6Q05KRzVQbjhDejBfYS1yamxnSjUyQ2gwYl80TQ=="proto: Object
asyncGeneratorStep @ asyncToGenerator.js?1da1:6
_throw @ asyncToGenerator.js?1da1:29
Promise.then (async)
asyncGeneratorStep @ asyncToGenerator.js?1da1:13
_next @ asyncToGenerator.js?1da1:25
eval @ asyncToGenerator.js?1da1:32
eval @ asyncToGenerator.js?1da1:21
updateResults @ HomeView.vue?409a:166
navigator.geolocation.getCurrentPosition.enableHighAccuracy @ HomeView.vue?409a:150
stream.js?553e:64 WebSocket connection to 'wss://no-credentials-available/' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED

Any thoughts / suggestions?

Thanks,

Bill

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.