GitHub - ofekats/Cloud_Computing_Final_Assignment: This project involves creating a social network with various AWS components. · GitHub
Skip to content

ofekats/Cloud_Computing_Final_Assignment

 
 

Repository files navigation

Social Network User System

Contributors

Overview

This project comprises two main parts, each implementing essential features for a social network. The system is built using AWS services such as Lambda, CDK, API Gateway, S3, DynamoDB, Textract, and SQS.
The primary objectives are to establish a foundational user system and introduce an innovative feature for post creation through image uploads and text extraction.

Setup

Prerequisites

  • Node.js and npm installed
  • AWS CLI configured with appropriate credentials
  • AWS CDK installed globally

Install AWS CLI

# Download the AWS CLI 
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" 
# Unzip the package
unzip awscliv2.zip 
# Install the AWS CLI
sudo ./aws/install 
# Clean up the installation files 
rm -rf awscliv2.zip aws

Set your Credentials

Inside Launch AWS Academy Learner Lab section go to AWS Details and then click on show close to the AWS CLI. copy the credentials. and write nano ~/.aws/credentials then paste the credentials. for verification, just writeaws s3 ls and make sure that you see some s3 bucket from you account.

Install AWS CDK

# Install Typescript
npm -g install typescript

# Install CDK
npm install -g aws-cdk

# Verify that CDK Is installed
cdk --version

Bootstrap your account for CDK

Note that: If you already bootstrap your account, no need to execute that action

# Go to CDK Directory
cd SocialNetwork-cdk

# Install NPM models
npm install

# Run bootsrap
cdk bootstrap --template bootstrap-template.yaml

Create a VPC

Our cdk doesn't create VPC, you will need to create it manually once.
Those are the settings you need to choose:

  • IPv4 CIDR block : 10.0.0.0/16
  • IPv6 CIDR block: No IPv6 CIDR block
  • Tenancy: Default
  • Number of Availability Zones (AZs): 2
    • First availability zone: us-east-1a
    • Second availability zone: us-east-1b
  • Number of public subnets: 2
  • Number of private subnets: 2
    • Public subnet CIDR block in us-east-1a : 10.0.0.0/24
    • Public subnet CIDR block in us-east-1b : 10.0.1.0/24
    • Private subnet CIDR block in us-east-1a : 10.0.2.0/24
    • Private subnet CIDR block in us-east-1b : 10.0.3.0/24
  • NAT gateways ($):
    • None (we create NAT with the cdk)
  • DNS options:
    • Enable DNS hostnames
    • Enable DNS resolution

Deploy the Base Stack

Make sure that you are at folder SocialNetwork-cdk Change the Account ID and the VPC ID for your own details, you can find all the places easily when searching TODO Account Details (in lib and bin folders)

# Install NPM models if you haven't already
npm install

#Deploy stack
cdk deploy

Part A: Build a basic user system

Overview

In this part we implement the foundational user system for a social network. The system includes APIs for creating, retrieving, and deleting users, as well as uploading profile pictures securely. The project is built using AWS services such as Lambda, CDK, API Gateway, S3, and DynamoDB.

Lambdas

Registration

A Lambda function that receives a username, email, password, and full name, then creates a user in the DynamoDB user’s table with the hashed password.

  • API Endpoint: /registration
  • Method: POST
  • Request:
    {
      "username": "user123",
      "email": "user@example.com",
      "password": "password123",
      "fullName": "User Fullname"
    }

Get User By ID

A Lambda function that retrieves user information by username from the DynamoDB user’s table.

  • API Endpoint: /getUser
  • Method: GET
  • Response:
    {
      "username": "user123",
      "email": "user@example.com",
      "fullName": "User Fullname",
      "validProfilePicture": true
    }

Delete User By ID

A Lambda function that deletes a user by username from the DynamoDB user’s table.

  • API Endpoint: /deleteUser
  • Method: DELETE

Get Pre-signed URL for Uploading Profile Image

A Lambda function that generates and returns a PUT pre-signed URL for uploading a profile image into the S3 bucket named "ImageStorage".

  • API Endpoint: /getPresignUrlForUplodingProfileImage
  • Method: GET
  • Response:
    {
      "uploadUrl": "https://s3.amazonaws.com/ImageStorage/..."
    }

Update DB Profile Picture

A Lambda function that gets triggered when an image is uploaded to the "ImageStorage" S3 bucket, then updates the DynamoDB user’s table with a valid profile picture flag and the URL to the image in the bucket.

  • Triggered by: S3 Bucket

Technologies Used

  • AWS Lambda
  • AWS CDK
  • AWS API Gateway
  • AWS S3
  • AWS DynamoDB
  • Node.js
  • Axios

How to run tests:

Navigate to Tests folder

cd Tests

installation

  • npm install --save-dev jest
  • npm install axios

Test command

chmod +x runTests.sh && ./runTests.sh

Diagram - Upload User Profile Picture

Diagram Part A -  Upload User Profile Picture

Part B: Innovative Feature

Overview

In this part, an innovative feature for our social network is implemented that allows users to upload posts by submitting images.
Amazon Textract is utilized to extract text from the uploaded images, allowing users to edit the extracted text before finalizing and uploading the post.
This feature includes multiple Lambda functions, SQS queues, and a DynamoDB table to manage the posts.

Lambdas

Get Pre-signed URL for Uploading Post Image

A Lambda function that generates and returns a PUT pre-signed URL for uploading an image into the posts S3 bucket.

  • API Endpoint: /getPresignUrlForUplodingPostImage
  • Method: GET
  • Response:
    {
      "uploadUrl": "https://s3.amazonaws.com/PostImages/..."
    }

Get Pre-signed URL for Viewing Profile Image

A Lambda function that generates and returns a GET pre-signed URL for viewing the user's profile picture.

  • API Endpoint: /getPresignUrlForViewingProfileImage
  • Method: GET
  • Response:
    {
      "uploadUrl": "https://s3.amazonaws.com/ImageStorage/..."
    }

Get All Done Posts

A Lambda function that returns all posts with the status 'done'.

  • API Endpoint: /getAllDonePosts
  • Method: GET
  • Response:
      [
        {
          "postId": "12345",
          "username": "user123",
          "content": "Extracted and edited content",
          "status": "done"
        },
        ...
      ]

Delete Post

A Lambda function that deletes a post by post ID from the DynamoDB posts table.

  • API Endpoint: /deletePost
  • Method: DELETE

Get Staging and Error Posts

A Lambda function that returns all posts with the status 'staging' or 'error' for a specific user.

  • API Endpoint: /getStagingAndErrorPosts
  • Method: GET
  • Response:
      [
        {
          "postId": "12345",
          "username": "user123",
          "content": "Extracted content",
          "status": "staging"
        },
        ...
      ]

Upload Post By Image After Edit

A Lambda function that updates the content of a post by post ID and changes the status to 'done' in the DynamoDB posts table.

  • API Endpoint: /uploadPostByImageAfterEdit
  • Method: POST
  • Request:
      {
        "postid": "123123"
        "content": "Edited content"
      }

Upload Text Post

A Lambda function that creates a new text post in the DynamoDB posts table.

  • API Endpoint: /uploadTextPost
  • Method: POST
  • Request:
      {
        "username": "user123",
        "content": "This is a text post"
      }

User Login

A Lambda function that checks whether the provided username and password are correct.

  • API Endpoint: /login
  • Method: POST
  • Request:
      {
        "username": "user123",
        "password": "password123"
      }

Textract Image

A Lambda function triggered by an SQS event to use Amazon Textract to extract text from an image and send the result to another SQS queue.

  • Triggered by: SQS

Store Post From SQS to DB

A Lambda function triggered by an SQS event with the extracted text to create a new record in the DynamoDB posts table.

  • Triggered by: SQS

Empty Bucket

A Lambda function to empty S3 buckets – only for destroy purposes.

Technologies Used

  • Amazon Textract
  • AWS SQS
  • AWS Lambda
  • AWS CDK
  • AWS API Gateway
  • AWS S3
  • AWS DynamoDB
  • Node.js

Diagram - Upload A Post By An Image

Diagram Part B -  Upload A Post By An Image

Running HTML pages locally

Navigate to Client-Side folder

cd Client-Side
  • first download http-server
npm install -g http-server
  • After you deployed the stack, you need to update in every html page the variable "baseURL" with updated apigateway URL (you see this after the deployment is done) image

  • Then run the following command

http-server -p 8000 --cors -c-1

Demo

Videos

Demo.1.mp4
Demo.2.mp4

Screenshots

Login page

login

Register page

register

Profile page

profile

Homepage page

homepage

Uploading Posts page

upload a post upload a post - edit

Notes:

How to create a package for lambda function

npm init -y
npm install aws-sdk

How to upload an image via CMD using curl

curl -X PUT -T "file path" "pre-signed URL"

About

This project involves creating a social network with various AWS components.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

  • JavaScript 84.5%
  • HTML 9.7%
  • TypeScript 5.7%
  • Shell 0.1%