S3 Proxy API

A simple S3 proxy service that generates signed URLs for uploading and downloading files from AWS S3.

Setup

Environment Variables

You need to set the following environment variables in your Val Town settings:

  • AWS_ACCESS_KEY_ID - Your AWS access key ID
  • AWS_SECRET_ACCESS_KEY - Your AWS secret access key
  • AWS_S3_BUCKET - The S3 bucket name to use
  • AWS_REGION - AWS region (optional, defaults to us-east-1)

AWS IAM Permissions

Your AWS credentials need the following S3 permissions:

  • s3:GetObject
  • s3:PutObject

API Endpoints

POST /upload

Generate a signed URL for uploading a file to S3.

Request:

{ "objectId": "my-file.jpg" }

Response:

{ "signedUrl": "https://bucket.s3.amazonaws.com/my-file.jpg?...", "objectId": "my-file.jpg", "expiresIn": 3600 }

POST /download

Generate a signed URL for downloading a file from S3.

Request:

{ "objectId": "my-file.jpg" }

Response:

{ "signedUrl": "https://bucket.s3.amazonaws.com/my-file.jpg?...", "objectId": "my-file.jpg", "expiresIn": 3600 }

Usage Examples

Upload a file

  1. Call /upload with the desired object ID
  2. Use the returned signed URL to PUT your file directly to S3
  3. The signed URL expires in 60 minutes

Download a file

  1. Call /download with the object ID
  2. Use the returned signed URL to GET the file directly from S3
  3. The signed URL expires in 60 minutes

Error Handling

The API returns appropriate HTTP status codes:

  • 200 - Success
  • 400 - Bad request (missing objectId)
  • 500 - Server error (missing config, AWS errors)