/Serveless-web-app

HorsesRides is a serverless web application for ride booking, integrating AWS Amplify, Cognito, API Gateway, Lambda, and DynamoDB.

MIT LicenseMIT

AWS Serverless Web App: HorsesRides

Description

HorsesRides is a web application for requesting rorses rides from Wild Rydes. It showcases serverless AWS technologies, offering user authentication and real-time ride management.

Features

  • User Authentication
  • Interactive Ride Booking
  • Real-time Ride Management

AWS Services

  • CodeCommit
  • Identity and Access Management (IAM)
  • Amplify
  • Cognito
  • API Gateway
  • Lambda
  • DynamoDB

Application Architecture

The serverless architecture for this web application is built upon several AWS services:

  • AWS Amplify: Serves as the foundation, hosting the static web content. It's the first interaction point for users, delivering HTML, CSS, and JavaScript to their browsers.
  • AWS Cognito: The second layer of user interaction, handling authentication. It ensures that users are securely logged in before interacting with backend services.
  • AWS API Gateway: Acts as the intermediary for all dynamic API calls over HTTPS from the client, enabling communication between the web browser and AWS Lambda.
  • AWS Lambda: The compute layer, it processes the application logic in response to API calls and interacts with the database.
  • AWS DynamoDB: Maintains a robust NoSQL database for storing ride data, interacted with by Lambda functions.

Setup and Installation

Part 1: Host a Static Website

AWS Services:

  • AWS CodeCommit for code storage.
  • AWS IAM for permission handling.
  • AWS Amplify for web hosting.

1. Create a Git Repository:

  • Start by creating a repository named “wildrydes-site” in AWS CodeCommit.
  • In AWS IAM, create a new user, e.g., TTTAdmin, and attach the AWSCodeCommitPowerUser policy for CodeCommit access.
  • Generate Git credentials for HTTPS connections to CodeCommit.

2. Configure the Git Repository:

  • Clone your new repository using AWS CloudShell.
  • Use Git commands to copy static files from S3, then add, commit, and push these files.

3. Enable Web Hosting with AWS Amplify:

  • Set up a new web app in AWS Amplify linked to your CodeCommit repository.
  • Follow the prompts to deploy your website.

Part 2: Create User Pool in Cognito

AWS Service: AWS Cognito for user management.

1. Create an AWS Cognito User Pool:

  • Create a user pool named “WildRydes” with default settings.
  • Save the User Pool ID and Client ID.

2. Update the Website Config File:

  • Adjust js/config.js with the userPoolId and userPoolClientId from Cognito.

Part 3: Build a Serverless Backend

AWS Services:

  • AWS DynamoDB for data storage.
  • AWS Lambda for backend processing.

1. Create an Amazon DynamoDB Table:

  • Create a table named “Rides” with “RideId” as the partition key.

2. Create an IAM Role for Lambda:

  • Set up a role in IAM for Lambda, granting necessary permissions for DynamoDB access.

3. Create a Lambda Function:

  • In AWS Lambda, establish a function named “RequestUnicorn.”
  • Assign the IAM role and deploy the function with requestUnicorn.js code.

Part 4: Deploy a RESTful API

AWS Service: AWS API Gateway.

1. Create a REST API:

  • In API Gateway, establish a new API named “WildRydes.”

2. Create an Authorizer:

  • Set up a Cognito authorizer and test it with an Authorization Token.

3. Create a New Resource and Method:

  • Add a 'ride' resource with a POST method, integrated with the Lambda function.
  • Set the Cognito authorizer for the method.

4. Deploy Your API:

  • Deploy the API by creating a stage named 'dev'.
  • Note the Invoke URL for future use.

5. Update the Website Config:

  • In js/config.js, update the invokeUrl with the URL from the API Gateway.

Screenshots/Demo

Acknowledgments

For a more detailed tutorial, I have created this guide in a Notion page: Link

This project was inspired by the AWS tutorial on building a serverless web application: Build a Serverless Web Application.