Effective total cost: $3–5/mo
Decide on an EC2 instance type:
- At AWS Console → EC2 → Instance Types, filter for ≥1 GB RAM and sort by price.
- t4g.micro is lowest.
- Look up what t4g.micro means:
- t: general-purpose with a burstable CPU quota
- 4: the current generation
- g: ARM architecture
- micro: the second lowest configuration
- Calculate cost:
- $6.15/mo when paying hourly
- $3.59mo when paying annually
- $2.31/mo when paying every 3 years
Prepare your AWS account:
- Set up an alarm for your estimated monthly bill so you're notified early of any unanticipated expenses.
- Import your SSH public key. (EC2 → us-west-2 → Key pairs)
Have ready:
- a domain name and DNS host
- an outgoing mail server
- I use AWS SES since it's easy (decent reputation, automatic DKIM, etc.) and inexpensive ($0.01/mo), but any SMTP provider will do, and you could also set up a traditional mail server on the EC2 instance.
- static file storage/hosting
- I use AWS S3 ($1/mo), but a variety of providers offer "S3-compatible" service, and you could also just use the filesystem on the EC2 instance.
Start an EC2 instance:
- Launch an instance (EC2 → us-west-2 → Instances) with:
- Name:
Mastodon
- Image: Ubuntu Server 22.04 LTS (HVM), SSD Volume Type (64-bit ARM)
- Type: t4g.micro
- Auto-assign public IP: Disable
- Security Group:
- Name:
Mastodon
- SSH from anywhere
- HTTP from anywhere
- HTTPS from anywhere
- Name:
- Storage: 8 GiB standard (HDD, $0.40/mo)
- Termination protection: Enable
- Credit specification: Standard
- Name:
- At EC2 → us-west-2 → Elastic IPs, allocate and associate a static IP address.
- Publish an A record at your preferred DNS host.
Prepare the host:
- SSH in as
ubuntu
. - Add 1 GB of swap:
- Make a swap file at
/swapfile
. - Add a swap entry in
/etc/fstab
.
- Make a swap file at
- Add swap on compressed RAM:
- Install package
systemd-zram-generator
. - Set
zram-fraction = 1
andcompression-algorithm = zstd
in/etc/systemd/zram-generator.conf
.
- Install package
- Configure unattended upgrades:
- Enable
Automatic-Reboot
in/etc/apt/apt.conf.d/50unattended-upgrades
.
- Enable
- Update and upgrade packages.
- Reboot.
Install Mastodon:
- Follow Mastodon's instructions.
- To tune PostgreSQL, set:
effective_cache_size = 256MB
- Tune Node.js to use enough memory:
- Set
export NODE_OPTIONS='--max-old-space-size=1024'
in~mastodon/.bashrc
.
- Set
- When editing
.env.production
, pay particular attention to:LOCAL_DOMAIN
SINGLE_USER_MODE
SMTP…
S3…
andAWS…
- When registering services, set:
- mastodon-sidekiq:
--concurrency 1
- mastodon-web:
MAX_THREADS=2
andWEB_CONCURRENCY=1
- mastodon-sidekiq:
- To tune PostgreSQL, set:
- Schedule the recommended periodic cleanup tasks.
- Set
--concurrency 1
on both tasks.
- Set
- Reboot.
- Sign in to the web interface and review/configure admin settings.
Try out the setup for a few days/weeks, then commit to a longer payment term:
- At EC2 → Reserved Instances → Purchase, filter for t4g.micro, sort by effective rate, and purchase a reservation.
- Wait a few hours for payment processing to complete.
- At EC2 → Reserved Instances, confirm that the reservation is active.
I am having a lot of difficulty getting mine to use SES for email.
I have the SMtP credentials correct, but I am not sure the other settings. Can you share your email settings (minus credentials of course)?
Here is mine:
SMTP_SERVER=email.us-east-2.amazonaws.com
SMTP_PORT=587
SMTP_LOGIN=-username-
SMTP_PASSWORD=-password-
#SMTP_SSL=true
#SMTP_ENABLE_STARTTLS_AUTO=false
SMTP_AUTH_METHOD=plain
SMTP_OPENSSL_VERIFY_MODE=none
SMTP_FROM_ADDRESS='Mastodon <notifications@-mydomain->'
I have verified DKIM and the account shows healthy. I have not "created a configuration set" or any tags.