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.
- Node.js and npm installed
- AWS CLI configured with appropriate credentials
- AWS CDK installed globally
# 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 awsInside 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 Typescript
npm -g install typescript
# Install CDK
npm install -g aws-cdk
# Verify that CDK Is installed
cdk --versionNote 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.yamlOur 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
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 deployIn 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.
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" }
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 }
A Lambda function that deletes a user by username from the DynamoDB user’s table.
- API Endpoint: /deleteUser
- Method: DELETE
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/..." }
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
- AWS Lambda
- AWS CDK
- AWS API Gateway
- AWS S3
- AWS DynamoDB
- Node.js
- Axios
Navigate to Tests folder
cd Tests- npm install --save-dev jest
- npm install axios
chmod +x runTests.sh && ./runTests.shIn 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.
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/..." }
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/..." }
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" }, ... ]
A Lambda function that deletes a post by post ID from the DynamoDB posts table.
- API Endpoint: /deletePost
- Method: DELETE
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" }, ... ]
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" }
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" }
A Lambda function that checks whether the provided username and password are correct.
- API Endpoint: /login
- Method: POST
- Request:
{ "username": "user123", "password": "password123" }
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
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
A Lambda function to empty S3 buckets – only for destroy purposes.
- Amazon Textract
- AWS SQS
- AWS Lambda
- AWS CDK
- AWS API Gateway
- AWS S3
- AWS DynamoDB
- Node.js
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)

-
Then run the following command
http-server -p 8000 --cors -c-1Demo.1.mp4
Demo.2.mp4
npm init -y
npm install aws-sdkcurl -X PUT -T "file path" "pre-signed URL"





