Skip to content

Commit

Permalink
Merge pull request #4 from ambujraj/dev
Browse files Browse the repository at this point in the history
Added terraform and initiateUpload and minor changes
  • Loading branch information
ambujraj authored Jan 13, 2024
2 parents 4b70c60 + f367e64 commit 59e66b7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-1
aws-region: us-east-2

- name: Set up SAM CLI
uses: aws-actions/setup-sam@v1
Expand All @@ -40,4 +40,4 @@ jobs:
rm python-site-packages.zip
env:
AWS_DEFAULT_REGION: us-west-1
AWS_DEFAULT_REGION: us-east-2
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ middleware/__pycache__
middleware/.venv
ui/node_modules
middleware/.aws-sam
middleware/python-site-packages.zip
middleware/python-site-packages.zip
.terraform
.terraform.lock.hcl
terraform.tfstate
terraform.tfstate.backup
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,35 @@
## Local Setup
1. Clone the repository
```bash
git clone https://github.com/ambujraj/ByteShare.git
git clone https://github.com/ambujraj/ByteShare.git
```
2. Install UI dependencies
2. Install Terraform
3. Configure your AWS account
```bash
aws configure
```
4. Create AWS resource using Terraform
```bash
cd ByteShare
terraform init
terraform plan
terraform apply
```
5. Install UI dependencies
```bash
cd ui
npm install
cd ..
```
3. Install Middleware(Backend) dependencies
6. Install Middleware(Backend) dependencies
```bash
cd middleware
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r requirements.txt
cd ..
```
4. Run the application
7. Run the application
```bash
cd ui
npm start
Expand Down
26 changes: 26 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
provider "aws" {
region = "us-east-2"
}

# S3 Bucket
resource "aws_s3_bucket" "byteshare-blob" {
bucket = "byteshare-blob"
}

# DynamoDB table
resource "aws_dynamodb_table" "byteshare-files-metadata" {
name = "byteshare-files-metadata"
billing_mode = "PAY_PER_REQUEST"
hash_key = "upload_id"
range_key = "timestamp"

attribute {
name = "upload_id"
type = "S"
}

attribute {
name = "timestamp"
type = "S"
}
}
20 changes: 19 additions & 1 deletion middleware/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from fastapi.middleware.cors import CORSMiddleware
from mangum import Mangum
import boto3
import uuid


app = FastAPI()
Expand All @@ -16,12 +17,15 @@
allow_headers=["*"],
)

# S3 client
s3_client = boto3.client("s3")
S3_BUCKET_NAME = "byteshare-blob"


@app.get("/health")
def health_check():
"""
Perform checks to verify system health.
For instance, check database connection, external services, etc.
Parameters:
Expand All @@ -34,5 +38,19 @@ def health_check():
return {"status": "ok", "details": "Service is running"}


@app.post("/initiateUpload")
def initiate_upload_return_presigned_url(file_name: str):
upload_id = uuid.uuid4().hex

presigned_url = s3_client.generate_presigned_url(
"put_object",
Params={"Bucket": S3_BUCKET_NAME, "Key": file_name},
ExpiresIn=10800,
HttpMethod="PUT",
)

return {"presigned_url": presigned_url, "upload_id": upload_id}


# Create a Handler from FastAPI for lambda.
handler = Mangum(app)
2 changes: 1 addition & 1 deletion middleware/samconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = 0.1
stack_name = "sam-byteshare-prod"
resolve_s3 = true
s3_prefix = "sam-byteshare-prod"
region = "us-west-1"
region = "us-east-2"
confirm_changeset = false
capabilities = "CAPABILITY_IAM"
parameter_overrides = "LamdbaLayerName=\"byteshare-dependencies\""
Expand Down
2 changes: 1 addition & 1 deletion ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function App() {
return (
<div className="App">
<header className="App-header">
<h3>Hi from ByteShare</h3>
<h6>Hi from ByteShare</h6>
</header>
</div>
);
Expand Down

0 comments on commit 59e66b7

Please sign in to comment.