DEV Community

Bulent Kocaman for PD Modules

Posted on

Selling Amazon EC2 cloud servers from WHMCS

Sooner or later a customer asks for something a fixed-size VPS can't give them: a Windows server, more memory than CPU, a region near their users, a disk that grows without a rebuild. That's when Amazon EC2 earns a place in your WHMCS catalogue.

EC2 is also the AWS service most likely to cost you money you never bill for. An EC2 server is a bundle of separate AWS resources, and each of them can outlive the service it belonged to. This post covers how to sell EC2 from WHMCS so that the product is flexible for the customer and predictable for you.

Instance types are not VPS plans

A simple VPS product sells a plan: a fixed bundle of CPU, memory, disk and transfer at one price. EC2 sells the parts separately:

  • the instance type (for example a general-purpose, compute-optimised or memory-optimised size) sets CPU and memory, billed while the instance runs;
  • the root disk and any extra disks are EBS volumes, billed by size for as long as they exist;
  • the public IPv4 address is billed on its own;
  • data transfer out is metered;
  • Windows images carry licensing in their running cost.

So an EC2 product in WHMCS is a base product plus configurable options, and your price has to cover every part. Sell it like a VPS with one number and the disks, addresses and transfer come out of your margin.

The AWS side

Use a dedicated IAM user with API access only. No console sign-in, and only the EC2 actions your provisioning needs: launching, starting, stopping, resizing and terminating instances, plus key pairs, security groups, addresses, volumes, images, metrics and pricing reads. A policy like that usually applies to every EC2 resource in the account rather than to named ones, so the cleanest isolation is a separate AWS account used only for reselling. If the key leaks, it can't touch your own infrastructure.

Pick a default region for your catalogue, and launch regions per product. Not every instance type exists in every region, and image IDs (AMIs) are per region too. A size you list for London may simply not exist in another region you offer. Check instance-type availability per region before you put a region on the order form.

Know your Elastic IP quota. AWS gives each account five Elastic IP addresses per region by default. If every server you sell gets a fixed address, your sixth order in a region will hit that limit. Request a quota increase before you launch, not after the first failed order.

Building the product in WHMCS

Store the access key in a server record. Under System Settings → Servers, the access key ID and secret go into the username and password fields, which WHMCS keeps encrypted. Put the server in a server group and assign that group to your EC2 products.

Use the generic product type. An EC2 server isn't a control-panel hosting account. Choose Other Products/Services; the server and VPS types add hostname, root-password and nameserver fields the order form doesn't need, and they can get in the way at checkout.

Turn on automatic setup. On the product's Module Settings tab, set Automatically setup the product to When the first payment is received. WHMCS leaves it off by default, and with it off a paid order becomes an Active service with nothing behind it and no error anywhere.

Set sensible defaults, then expose only the choices worth selling. Each product needs a default region, instance type, image, root disk size and, optionally, a startup script. Then decide what customers choose at checkout through configurable options: region, instance type, operating system, extra storage, backup retention, and how many backups they can keep. Hide anything you'd rather fix per product.

Track images by family, not by AMI ID. AWS publishes patched images regularly, and old AMIs get deprecated. If your configurable option points at a specific AMI ID, customers get an ageing image and eventually a broken order. Store an OS family such as "Ubuntu 24.04 LTS" and resolve it to the newest image for the launch region at order time.

Watch for retirements. AWS retires instance types and images. Check your option lists against the live catalogue on a schedule, daily is plenty, and hide retired choices without touching customers already on them.

Access the customer actually needs

  • Linux: create an SSH key pair per server, give the customer the private key once, and tell them the default login user for that image. It isn't always root: Ubuntu images use ubuntu, Amazon Linux uses ec2-user, and other distributions have their own.
  • Windows: the security group must allow Remote Desktop, and the customer signs in as Administrator. Decide how you hand over that first password securely, because it shouldn't sit on a web page.

Give every server its own security group. That's the firewall in EC2. One customer's rule change then can't open another customer's ports, and customers can manage their own rules from the client area.

Attach an Elastic IP. A normal public IPv4 address changes every time an EC2 instance is stopped and started. An Elastic IP stays put, so the customer's DNS records and saved connections keep working after a stop.

Where the bill hides

Stopped still costs money. AWS doesn't charge instance usage while an instance is stopped, but the EBS volumes keep billing. Public IPv4 addresses are charged too: AWS charges for every public IPv4 address, Elastic IPs included, whether attached to a running server or sitting idle. Stopping a server for an unpaid invoice cuts the compute cost, not the whole cost.

Extra disks survive termination by default. EC2 deletes the root volume when an instance is terminated, but keeps other attached EBS volumes unless they're set otherwise. Terminate the instance alone and the customer's extra storage keeps billing.

Backups outlive the server. An AMI backup is backed by EBS snapshots, and deregistering the image doesn't delete them by default. Cap how many backups a customer can keep, and sell more as an option.

Transfer is metered. Data out to the internet is billed by AWS. Either include a sensible amount in the price or record each server's monthly transfer in WHMCS and bill overage with WHMCS's own bandwidth settings.

Upgrades need a stop. AWS can only change the instance type of a stopped instance. An Upgrade/Downgrade in WHMCS should stop, resize and start the server, and the customer should know it will be briefly offline.

Suspension and termination

Treat them as two different tools:

  • Suspend stops the instance and keeps every byte. It's the right first response to a late payment, but the disks and address are still on your bill.
  • Terminate should remove everything the server brought with it: the instance, the Elastic IP (released, not just detached), the security group, the key pair, extra volumes and backups. Then check that AWS confirms each piece has gone.

Finally, make sure the WHMCS cron runs often. Several finishing steps, such as attaching the Elastic IP or a new disk, happen a few minutes after the instance launches.

The module we built for this

PD AWS EC2 is our WHMCS module for this. An order launches the instance; suspend stops it, unsuspend starts it and terminate deletes it. Terminating releases the Elastic IP and removes the security group, key pair, extra disks and backups, so nothing keeps billing. Images are tracked by family, so each order launches the latest patched image for its region, and a daily check flags instance types and images AWS has retired so you can hide them with one click of Sync. Windows servers get an RDP-ready firewall; Linux servers get an SSH key and the right default login user for the image.

It generates the configurable options from your AWS catalogue, and its Price Analysis screen shows the Linux On-Demand cost of each instance type in your default region next to a suggested price at your margin. Use it as your starting point, then add your own amounts for disks, the address, Windows licensing and transfer. Customers get power controls, connection details, their own firewall rules, extra volumes, usage graphs, backups and an optional in-browser console. It installs and updates from the PD Modules panel inside WHMCS, and an update that fails rolls itself back.

For requirements and screenshots, see the PD AWS EC2 module page.

This post is part of a series on reselling AWS from WHMCS; start with the overview.

Questions about selling EC2 from WHMCS are welcome in the comments.

PD Modules is made by Projektif Digital Ltd, the team behind PD Hosting.

Top comments (0)