Giter Site home page Giter Site logo

social's Introduction

Social Media Backend Example

About

An example social media backend using AWS. This project demonstrates the use of an API using a ECS cluster and RDS backend. The API is publicly accessible using a custom domain configuration for API gateway. The API gateway uses a VPC link to reach a services within a private VPC across multiple subnets. Traffic is sent to an application load balancer then to ECS. ECS uses Secrets Manager to obtain credentials to connect to RDS. The project is designed for use with a hybrid of local and cloud development.

sample image

Usage

Requirements

  • Setup credentials for AWS CLI
  • Create a file ./terraform/terraform.tfvars and populate it using variables described in ./terraform/variables.tf

Local Development

The ECS image can be developed and tested locally using a local PostgreSQL database using docker compose.

  • Run docker compose build to build image for the ECS container.
  • Start up docker compose with docker compose up -d to run local PostgreSQL and ECS container.

Cloud Development

Use infrastructure as code to create AWS services.

Initialize terraform.

terraform init

Create infrastructure.

terraform apply

Build and tag ECS image with name of your ECR repo url that was output from terraform.

docker build -t <ecr-repo-url>:latest .

Authenticate docker

aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com

Push to ECR

docker push <ecr-repo-url>:latest

Optional

Taskfiles have been included in the project to quickly run preconfigured build and run scripts. Install taskfile and run task --list-all to view commands available in a given directory.

API Usage

Users

POST /users

Create a new user.

curl -X POST -H "Content-Type: application/json" \
  -d '{"username":"John123","profileName":"Johnny"}' \
  http://localhost:8080/users

# Response
{"userId":"23"}
GET /users/{:id}

Get a user

curl -X GET http://localhost:8080/users/3

# Response
{"username":"smith","profileName":"John Smith"}
PUT /users/{:id}

Update a user

curl -X PUT -H "Content-Type: application/json" \
  -d '{"username":"smith","profileName":"Elizabeth Smith"}' \
  http://localhost:8080/users/3
DELETE /users/{:id}

Delete a user

curl -X DELETE http://localhost:8080/users/3

Posts

GET /posts

Get posts

curl -X GET "http://localhost:8080/posts?id=1&last-id=0&size=5"

# Response
[{"postId":"4","body":"example post","likes":0},{"postId":"3","body":"another example post","likes":0},{"postId":"2","body":"post by user 1","likes":0},{"postId":"1","body":"yet another example post","likes":0}]
POST /posts

Create a new post

curl -X POST -H "Content-Type: application/json" \
  -d '{"userId":"4","body":"test post"}' \
  http://localhost:8080/posts

# Response
{"postId":"123"}
PUT /posts/{:post-id}

Update a post

curl -X PUT -H "Content-Type: application/json" \
  -d '{"body":"edited post"}' \
  http://localhost:8080/posts/123
DELETE /posts/{:post-id}

Delete a post

curl -X DELETE http://localhost:8080/posts/123

Comments

GET /comments

Get comments from a post with pagination

curl -X GET "http://localhost:8080/comments?id=2&last-id=1&size=5"

# Response
[{"postId":"2","username":"molly1234","body":"comment 5"},{"postId":"2","username":"molly1234","body":"comment 4"},{"postId":"2","username":"molly1234","body":"comment 3"},{"postId":"2","username":"molly1234","body":"comment 2"},{"postId":"2","username":"molly1234","body":"comment 1"}]
POST /comments

Create a new comment on a post

curl -X POST -H "Content-Type: application/json" \
  -d '{"userId":"5","postId":"3","body":"test comment"}' \
  http://localhost:8080/comments

# Response
{"commentId":"123"}
PUT /comments/{:comment-id}

Update a comment on a post

curl -X PUT -H "Content-Type: application/json" \
  -d '{"body":"updated comment"}' \
  http://localhost:8080/comments/123
DELETE /comments/{:comment-id}

Delete a comment on a post

curl -X DELETE http://localhost:8080/comments/11

Followers

GET /followers

Get followers with pagination

curl -X GET "http://localhost:8080/followers?id=4&last-id=2&size=5&following=true"

#Response
{"userIds":["3","5","6","7","8"],"usernames":["smith","123sarah","321Josh1","1Jjake","theChris"]}
POST /followers

Create a follower

curl -X POST -H "Content-Type: application/json" \
  -d '{"followerId":"3","followeeId":"5"}' \
  http://localhost:8080/followers
DELETE /followers

Delete a following relationship

curl -X DELETE -H "Content-Type: application/json" \
  -d '{"followerId":"4","followeeId":"5"}' \
  http://localhost:8080/followers

NewsFeed (TODO)

Get /feed

Get newsfeed for user with pagination

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.