Weshare.click (or weshare
for short) is a simple file-sharing application that you can self-host on AWS and use as an alternative to file-transfer services such as WeTransfer or Dropbox Transfer.
The first version of this application was built from scratch by Eoin and Luciano on a series of live streams as part of the AWS Bites show. The full playlist (6 episodes / ~8 hours) is available on YouTube.
The idea was to showcase how to build a real application using AWS, Serverless, and Node.js. The application is still minimal but usable.
Imagine that you have a file you want to share with others, or even with yourself on another device. You don't want to use Google Drive, Dropbox, or any of the public cloud services, perhaps because they are blocked in some way. This codebase will allow you to deploy your own, branded file-sharing service!
The feature set is still minimal, but it gives you a fully functional and usable backend.
If there's any feature that you'd like to see here, please submit an issue or, even better, a PR.
The current architecture makes use of the following services:
A high-level architecture diagram is available in this repository.
The CLI authentication uses the OAuth 2.0 device authentication flow, which is not supported by Cognito by default, so we built a shim on top of the built-in Cognito OAuth 2.0 code flow. A diagram that showcases how that works is available.
jq
: optional but useful if you need to run some of the suggested CLI commands belowThe first step is to get the code locally by cloning this repository:
git clone git@github.com:awsbites/weshare.click.git
cd weshare.click
Now you can run the following script to download the necessary dependencies for every package:
./setup.sh
Before deploying your weshare instance you need to provide some configuration.
To do that you have to create a file named config.cjs
at the root of the project with the following content:
// @ts-check
'use strict'
const { defineConfig } = require('./weshare.cjs')
exports.config = defineConfig({
// region: 'eu-west-1', // inferred from AWS_REGION or DEFAULT_AWS_REGION (or 'eu-west-1' if not set)
// stage: 'dev', // the name of the stage to deploy to (e.g. 'dev', 'prod')
// serviceName: 'weshare', // the name of the service (for resource naming)
domain: '' // <-- ADD YOUR DOMAIN NAME HERE (e.g. 'files.weshare.click' or 'weshare.click')
})
Note: If you don't like copy pasting you can instead run
mv config.cjs~sample config.cjs
)
You only need to specify the domain
name but you can also change the default region
and the stage
.
To deploy all the stacks you can run:
./deploy.sh
Warning: The first deployment will need some manual intervention. The deployment will create a new Route 53 hosted zone. You will need to make sure that the DNS are propagated correctly to that new Hosted Zone. This is something that needs to be done DURING THE FIRST DEPLOYMENT. In fact, the deployment will also create a certificate in ACM and it will try to validate it based on resolving some DNS on that hosted zone. Until ACM is able to validate the domain, your deployment will be pending. See below how to manually configure the Hosted zone.
If you know a better way to streamline the first deployment, please create an issue or a PR!
To be able to login into weshare, you need to create some users first. You can do this either from the AWS web console or programmatically.
Here's how to add a new user to the user pool from the AWS CLI:
export USER_POOL_NAME="weshare-user-pool-dev" # <-- update if you changed the `serviceName` or the `stage` in the config
export USERNAME="foo@bar.com" # <-- replace with the username you want to add (needs to be an email)
export TEMP_PASS="ChangeMeSoon(1234)" # <-- replace with the temporary password
export USER_POOL_ID=$(aws cognito-idp list-user-pools --max-results 60 | jq -r ".UserPools[] | select(.Name | contains(\"${USER_POOL_NAME}\")) | .Id")
aws cognito-idp admin-create-user --user-pool-id "${USER_POOL_ID}" --username "${USERNAME}" --temporary-password "${TEMP_PASS}"
If all went well you should receive an email with your temporary password. After the first login, you'll be requested to change the password.
weshare
CLI with npm i -g weshare
weshare login
weshare <filepath>
For more info use weshare --help
To remove this app from this account you need to:
./remove.sh
to remove all the stacksEveryone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.
Licensed under MIT License. © Luciano Mammino, Eoin Shanaghy.