lol sst can deploy a $5 vps quick example deploying an nginx docker image, less than 50 lines
self-hosting with sst on a $5 vps.
I’ve been using SST to deploy some of my projects to AWS for the past year. Some of these actually had more than 0 users. This + my shit code + AWS = 💸.
Safe to say I was waking up in the middle of the night drenched in sweat worrying about my AWS bill (or not really since they gave me $1000s of credits, but still). Luckily for me, SST recently released an update that allows me to become a $5 VPS guy.
I’m going to show you how to use SST to self-host Plunk with SST on Hetzner Cloud, all with a custom domain, HTTPS, and more. Even if you’re not interested in self-hosting Plunk, I think this guide can still be useful to help you figure out how to self-host other stuff with SST.
Set up AWS
Section titled: Set up AWSWorst things first, we have to set up AWS. Thankfully SST has a guide on how to set up your AWS account and manage your environments and credentials in a simple and secure way.
Set up Hetzner
Section titled: Set up HetznerI’m using Hetzner, but if you want to use Digital Ocean, or any of the other platforms out there, go ahead. I’m sure there’s a Pulumi provider out there and SST is just a Pulumi wrapper after all. For Hetzner all you’ll need to do is sign up, create a project, head to the security section, and create an API token. Put this token in your .env
file:
Set up Cloudflare
Section titled: Set up CloudflareWe’re going to use Cloudflare for our DNS. If you don’t have an account yet, go ahead and create one. Once you have an account, add your domain to Cloudflare and change your nameservers to the ones Cloudflare provides. Then create an API token by heading to your profile, then API tokens and clicking “Create token”. You can use the “Edit zone DNS” template. Once you’re done, copy the key and put it in your .env
file:
You’ll also need your Cloudflare email and account id, which you can find on your domain’s overview page on the top left and bottom right respectively. Put these in your .env
file as well:
Also, head over to the SSL/TLS section and set your SSL/TLS encryption mode to “Full (strict)”.
Set up SST
Section titled: Set up SSTFinally, we can set up SST. First, either install the CLI via npm:
or install it globally
Set up the project
Section titled: Set up the projectNow everything is set up, we can finally create our project and self-host Plunk. Create your sst.config.ts
file
First, let’s set up our server. Run sst add hcloud
and sst add tls
and add the following code to your run
function:
This will set up your server, install & enable Docker, and add the debian
user to the docker
group. To be honest, you should definitely change the userData
to something more secure (I’m new to this $5 VPS stuff ok, I still need to figure out how to harden servers myself), but this is just a tutorial.
Running sst deploy
will now deploy your server to Hetzner Cloud and log the server’s IP address to your console. You can connect to the server by running the following command:
According to Plunk’s self-hosting guide, we need to set up a few things:
- An SNS topic
- A configuration set
- AWS credentials
- Postgres
- Redis
- Plunk itself
- A subscription to SNS
Would you be surprised if I told you that you can do all of this with SST? I hope not, because you can. Run sst add aws
, sst add docker
, sst add random
. Update your app
function to be something like
You should change production
and development
to the names of your AWS profiles. You can also change the region
to your preferred region.
Then, add the following code to your run
function:
This will set up everything you need to self-host Plunk. Run sst deploy
and you should be able to view your self-hosted Plunk by visiting http://your.server.ip:3000
.
Adding a custom domain
Section titled: Adding a custom domainObviously you don’t want to use your server’s IP address to access Plunk over HTTP. With SST we can also set up Cloudflare to point a custom domain to our server and Caddy (or any other reverse proxy) to handle HTTPS. Run sst add cloudflare
and sst add command
and add the following code to your run
function:
Boom! Run sst deploy
and you can view your self-hosted Plunk by visiting https://plunk.example.com
(obviously replace example.com
with your domain).
Confirm the subscription
Section titled: Confirm the subscriptionUnfortunately, Plunk can’t automatically confirm the subscription to the SNS topic, so we need to do this manually.
SSH into your server and run docker ps
. Copy the id of the Plunk container and run docker logs -f <id>
.
Then, head over to the SNS console (click “Start with an overview” if it prompts you to create a topic), navigate to the subscription and click on “Request confirmation”. AWS will send a mock HTTP POST request to your Plunk endpoint and Plunk will recognise that you want to confirm the subscription and show you the URL to confirm it. Copy and paste it into your browser and you’re done!
Conclusion
Section titled: ConclusionAnd that’s it! You’ve now self-hosted Plunk with SST on a $5 VPS. You can now access Plunk by visiting https://plunk.example.com
.
There are probably loads of things you can do to improve this setup, but I hope this guide has given you a good starting point.
If you have any questions, feel free to ask me on 𝕏. I’ll also definitely be writing more about my experience with $5 VPSs and SST in the future (hardening your server, zero downtime deployments, etc.), so give me a follow if you’re interested in that.