A simple web service built in Go to facilitate file uploads to an AWS S3 bucket. This service is built using the Gin web framework, structured logging with logrus, and AWS SDK for Go.
-
Go installed on your machine.
-
Proper AWS credentials set either as environment variables (
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
) or configured via AWS CLI. -
An existing S3 bucket to which you have write permissions.
-
Clone the repository:
git clone [repository_url] cd [repository_directory]
-
Set the necessary environment variables:
# OPTIONAL (if using environment variables for AWS authentication) export AWS_ACCESS_KEY_ID=<your_aws_access_key_id> export AWS_SECRET_ACCESS_KEY=<your_aws_secret_key> export PORT=<desired_port> # REQUIRED export AWS_REGION=<your_aws_region> export BUCKET_NAME=<your_s3_bucket_name> export USERNAME=<basic_auth_username> export PASSWORD=<basic_auth_password>
-
Run the service:
go run main.go
Endpoint: POST /upload
Authentication: Basic Auth using the provided USERNAME
and PASSWORD
.
Form Data
-
file
: The file to be uploaded (sent as form data).
Parameters:
-
folder
(optional): S3 folder/directory in which to save the uploaded file. Defaults to "/" if not specified.
CURL Example:
curl -X POST -u $USERNAME:$PASSWORD -F "file=@/path/to/your/file.txt" "http://localhost:8080/upload?folder=your_folder_name"
The application uses structured logging with logrus, producing logs in JSON format for easy ingestion by log processing tools and platforms.