Skip to content

akash3911/Vaultbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—„οΈ VaultBox Setup Guide

Ultra-simple serverless file storage with just 3 files!

πŸ“‹ What You Need

  • AWS Account
  • 10-15 minutes

πŸ—οΈ Step-by-Step AWS Setup

1️⃣ Create S3 Bucket (File Storage)

  1. Go to S3 Console: https://console.aws.amazon.com/s3/
  2. Click "Create bucket"
  3. Bucket name: vaultbox-akash βœ… (already filled in)
  4. Region: Asia Pacific (Sydney) ap-southeast-2 βœ… (already selected)
  5. Settings:
    • βœ… Block all public access (keep default)
    • βœ… Enable versioning
    • βœ… Enable server-side encryption (AES-256)
  6. Click "Create bucket"

πŸ“ Note down: vaultbox-akash


2️⃣ Create DynamoDB Table (Metadata Storage)

  1. Go to DynamoDB Console: https://console.aws.amazon.com/dynamodb/
  2. Click "Create table"
  3. Table name: vaultbox-files
  4. Partition key: userId (String)
  5. Sort key: fileId (String)
  6. Settings: Use default settings (On-demand billing)
  7. Click "Create table"

πŸ“ Note down: Your table name (vaultbox-files)


3️⃣ Create Cognito User Pool (Authentication)

  1. Go to Cognito Console: https://console.aws.amazon.com/cognito/
  2. Click "Create user pool"
  3. Step 1 - Configure sign-in experience:
    • βœ… Email
    • βœ… Username
  4. Step 2 - Configure security requirements:
    • Password policy: Use defaults
    • MFA: No MFA (for simplicity)
  5. Step 3 - Configure sign-up experience:
    • βœ… Enable self-registration
    • Required attributes: Email
  6. Step 4 - Configure message delivery:
    • Email: Send email with Cognito (for testing)
  7. Step 5 - Integrate your app:
    • User pool name: vaultbox-users
    • App client name: vaultbox-web
    • βœ… Generate client secret: NO (uncheck this)
  8. Click "Create user pool"

πŸ“ Note down:

  • User Pool ID (e.g., us-east-1_xxxxxxxxx)
  • App Client ID (e.g., xxxxxxxxxxxxxxxxxxxxxxxxxx)

4️⃣ Create Lambda Function (Backend Logic)

  1. Go to Lambda Console: https://console.aws.amazon.com/lambda/
  2. Click "Create function"
  3. Function name: vaultbox-backend
  4. Runtime: Python 3.11
  5. Architecture: x86_64
  6. Click "Create function"

4.1 Add Lambda Code

  1. In the Code tab, delete the default code
  2. Copy and paste the entire content from your lambda_function.py file
  3. Click "Deploy"

4.2 Set Environment Variables

  1. Go to Configuration tab β†’ Environment variables
  2. Click "Edit"
  3. Add these variables:
    • S3_BUCKET_NAME: vaultbox-akash
    • DYNAMODB_TABLE_NAME: vaultbox-files
  4. Click "Save"

4.3 Update Lambda Role Permissions

  1. Go to Configuration tab β†’ Permissions
  2. Click on the execution role name (opens IAM)
  3. Click "Add permissions" β†’ "Attach policies"
  4. Search and select these policies:
    • AmazonS3FullAccess
    • AmazonDynamoDBFullAccess
  5. Click "Add permissions"

πŸ“ Note down: Your Lambda function ARN


5️⃣ Create API Gateway (HTTP API)

  1. Go to API Gateway Console: https://console.aws.amazon.com/apigateway/
  2. Click "Create API"
  3. Choose "REST API" β†’ "Build"
  4. API name: vaultbox-api
  5. Endpoint Type: Regional
  6. Click "Create API"

5.1 Create Cognito Authorizer

  1. Click "Authorizers"
  2. Click "Create New Authorizer"
  3. Name: cognito-auth
  4. Type: Cognito
  5. Cognito User Pool: Select your user pool from step 3
  6. Token Source: Authorization
  7. Click "Create"

5.2 Create Resource and Methods

  1. Click "Resources"
  2. Click "Actions" β†’ "Create Resource"
  3. Resource Name: files
  4. Resource Path: /files
  5. βœ… Enable API Gateway CORS
  6. Click "Create Resource"

5.3 Add POST Method (Upload)

  1. Select /files resource
  2. Click "Actions" β†’ "Create Method" β†’ "POST"
  3. Integration type: Lambda Function
  4. Lambda Function: Select your vaultbox-backend function
  5. Click "Save" β†’ "OK"

5.4 Add Authorization to POST

  1. Click on POST method
  2. Click "Method Request"
  3. Authorization: Select your Cognito authorizer
  4. Click the checkmark to save

5.5 Add GET Method (List Files)

  1. Select /files resource
  2. Click "Actions" β†’ "Create Method" β†’ "GET"
  3. Integration type: Lambda Function
  4. Lambda Function: Select your vaultbox-backend function
  5. Authorization: Select your Cognito authorizer
  6. Click "Save"

5.6 Create {fileId} Resource

  1. Select /files resource
  2. Click "Actions" β†’ "Create Resource"
  3. Resource Name: File Operations
  4. Resource Path: {fileId}
  5. βœ… Enable API Gateway CORS
  6. Click "Create Resource"

5.7 Add GET Method (Download URL)

  1. Select /{fileId} resource
  2. Click "Actions" β†’ "Create Method" β†’ "GET"
  3. Integration type: Lambda Function
  4. Lambda Function: Select your vaultbox-backend function
  5. Authorization: Select your Cognito authorizer
  6. Click "Save"

5.8 Add DELETE Method

  1. Select /{fileId} resource
  2. Click "Actions" β†’ "Create Method" β†’ "DELETE"
  3. Integration type: Lambda Function
  4. Lambda Function: Select your vaultbox-backend function
  5. Authorization: Select your Cognito authorizer
  6. Click "Save"

5.9 Deploy API

  1. Click "Actions" β†’ "Deploy API"
  2. Deployment stage: [New Stage]
  3. Stage name: prod
  4. Click "Deploy"

πŸ“ Note down: Your API Gateway URL (e.g., https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod)


6️⃣ Setup Cognito Hosted UI (User Authentication)

  1. Go back to Cognito Console
  2. Select your user pool
  3. Go to "App integration" tab
  4. Click on your app client
  5. Click "Edit" under "Hosted UI"
  6. Settings:
    • Allowed callback URLs: http://localhost:3000 (for testing)
    • Allowed sign-out URLs: http://localhost:3000
    • OAuth 2.0 grant types: βœ… Authorization code grant
    • OpenID Connect scopes: βœ… Email, βœ… OpenID, βœ… Profile
  7. Click "Save changes"

πŸ“ Note down: Your Cognito domain URL


7️⃣ Update Frontend (index.html)

  1. Open your index.html file
  2. Update these values:
// Replace with your actual values
const API_URL = 'https://YOUR-API-ID.execute-api.us-east-1.amazonaws.com/prod/files';
const COGNITO_DOMAIN = 'https://your-domain.auth.us-east-1.amazoncognito.com';
const CLIENT_ID = 'your-cognito-client-id';
const REDIRECT_URI = 'http://localhost:3000';

8️⃣ Test Your Application

  1. Serve your HTML file:

    # Simple Python server
    python -m http.server 3000
  2. Open browser: http://localhost:3000

  3. Test flow:

    • Click sign in β†’ Should redirect to Cognito
    • Create account β†’ Verify email
    • Sign in β†’ Should redirect back with token
    • Upload file β†’ Should work
    • Download file β†’ Should work
    • Delete file β†’ Should work

πŸŽ‰ You're Done!

Your VaultBox is now live with:

  • βœ… Secure file upload/download
  • βœ… User authentication via Cognito
  • βœ… Serverless auto-scaling
  • βœ… Encrypted storage in S3
  • βœ… Fast metadata in DynamoDB

πŸ”§ Troubleshooting

Common Issues:

  1. CORS Error: Enable CORS in API Gateway for all methods
  2. 403 Error: Check Cognito authorizer is attached to methods
  3. Lambda Error: Check CloudWatch logs in Lambda console
  4. File Upload Fails: Verify S3 bucket permissions in Lambda role

πŸ“Š Monitoring

View logs and metrics:

  • Lambda: CloudWatch logs automatically created
  • API Gateway: Built-in monitoring dashboard
  • S3: Storage metrics in S3 console
  • DynamoDB: Performance metrics in DynamoDB console

Total Setup Time: ~15 minutes Total Code: 3 files, ~150 lines Monthly Cost: Nearly free for development/testing!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors