跳到正文
DEV Community· h13ris·· 13 小時前AI 評分60

NCTF26 在 AWS 的託管用量共 $515.29,扣除抵免額後實付 $335.27

Running a national CTF on AWS: $515 of usage, $335 paid, and the bill line by line

AI 導讀

NCTF26 在 AWS 的雲端託管用量合共 $515.29,扣除 $180.02 抵免額後實付 $335.27,均為截至 2026 年 11 月 21 日的未計税美元金額。

正文

When you plan the infrastructure for a CTF, you worry about the event: the launch rush, the scoreboard at 3 a.m., player containers spawned on demand by people who are actively trying to break them.

Then the bill arrives, and the biggest line has little to do with the event itself.

This article is the bill of a national CTF, line by line, with the architecture that produced it. All figures come from AWS Cost Explorer as of 21 November 2026, in USD before tax. They cover cloud hosting only: not the venue, not the prizes, not anyone's time.

Context: NCTF26 in three lines

NCTF26 is the 4th edition of the National CTF of Togo, organized by CERT.tg. I was the technical lead.
It ran in two phases: a 29-hour online qualifier (6 Nov 19:00 → 7 Nov 23:59 UTC, more than 350 registered players, 60 teams on the final scoreboard, 19,175 submissions) and a 24-hour on-site final in Lomé (19 → 20 Nov, 10 teams, 47 players).
609 challenges were played across both phases. The public site, with writeups and the hall of fame, is still at ctf.tg.

The architecture: two machines and a lot of tunnels

The whole competition ran on two EC2 instances in the Paris region:

  • The front (ARM, Graviton t4g family): CTFd 3.8 with our own plugins, MariaDB, Redis, nginx, a tunnel server, and a small gateway for the AI challenges. Everything runs in Docker Compose except the tunnel server, which is a host service.
  • The arena (x86, c6i.4xlarge, 16 vCPU / 32 GB): a single-node Docker Swarm that runs every player instance, the per-team VPN gateways and, for the final, 31 shared multi-machine labs.

The key design choice: the arena has no public entry point for players. Everything a player reaches goes through the front. The arena dials out to the front through a tunnel, and CTFd drives the arena's Docker engine through a filtering broker that only allows the operations the instancer needs.

Diagram

Players reach their instance in one of three ways: an HTTPS URL on a random 16-character subdomain (80 bits, drawn at every launch), a raw TLS connection routed by server name, or a per-team WireGuard VPN for multi-port boxes. Never a bare IP:port; that rule gets its own article in this series.

What made this cheap is what is not there: no load balancer, no managed database, no Kubernetes control plane, no NAT gateway. Cloudflare's free plan sits in front of the site and the platform. S3 holds database dumps and the challenge images as tarballs, so the arena can be rebuilt with a docker load. Disks are encrypted gp3 volumes: 30 GB on the front, 100 GB on the arena.

The AI challenges were supposed to run on a GPU node with a local model server. The GPU quota for that instance family was refused in our region, so we moved them to Amazon Bedrock behind a small gateway that speaks the API the challenges expected. That detour ended up being one of the best cost decisions of the edition (see below).

The bill, month by month

Month Usage Credits Paid
September 2026 $6.89 −$6.89 $0
October 2026 $104.00 −$104.00 $0
November 2026 (to 21 Nov) $404.40 −$69.13 $335.27
Total $515.29 −$180.02 $335.27

September and October were development and test runs, with the machines mostly stopped between sessions. Credits covered all of that and ran out in early November. Everything we actually paid was paid in November.

The bill, line by line

Usage before credits, across the three months:

Component Sep Oct Nov Total Share
Arena (c6i) 4.54 79.52 299.82 383.88 74.5 %
Front (t4g) 0.43 7.44 58.31 66.18 12.8 %
EBS disks (30 + 100 GB) 0.88 9.94 8.13 18.95 3.7 %
Data transfer out 0 0 15.98 15.98 3.1 %
Public IPv4 addresses 0.95 4.55 4.87 10.37 2.0 %
Bedrock (AI challenges) 0.02 0 10.14 10.16 2.0 %
EBS snapshots 0 2.27 6.39 8.66 1.7 %
S3 0.07 0.27 0.70 1.04 0.2 %
Cost Explorer API 0 0 0.07 0.07 —

The same thing as a picture:

Arena (c6i)        ██████████████████████████████████████  $383.88  74.5%
Front (t4g)        ███████                                 $66.18   12.8%
EBS disks          ██                                      $18.95    3.7%
Data transfer out  ██                                      $15.98    3.1%
Public IPv4        █                                       $10.37    2.0%
Bedrock            █                                       $10.16    2.0%
Snapshots          █                                        $8.66    1.7%
S3                 ▏                                        $1.04    0.2%

A few lines deserve a comment.

The arena is three quarters of the bill. The rates observed on the bill: about $0.81/hour for the c6i.4xlarge, so $19.39 per full day. The front is cheap in comparison: about $1.80/day as a t4g.large, $7.22/day as a t4g.2xlarge.

Bedrock cost $10.16 for the whole edition, of which $7.49 on the busiest day of the qualifier. The alternative we had planned, a GPU instance with a local model server, was priced at $0.615/hour. Pay-per-token wins easily when the load is a few hundred players poking at prompts during two windows of about a day each.

Data transfer out is almost entirely the event: $15.98, all of it in November, of which $8.91 on 7 November alone.

Public IPv4 is now a real line: $10.37 for the public addresses of the two machines. And an Elastic IP that is allocated but not attached is still billed.

S3 is a rounding error: $1.04, even though the bucket held 52 GB at the end (dumps every 15 minutes during the competition, plus 318 image tarballs).

The bill, day by day: the event is not the expensive part

This is the part I did not expect. Here are the notable days:

Day(s) Cost What was happening
31 Oct → 5 Nov ≈ $22/day arena on continuously before the qualifier
7 Nov $42.44 qualifier: data transfer, Bedrock, front resized up
8 Nov $28.22 the day after: everything still running, front still large
9 Nov $4.19 arena stopped around 01:00, front shrunk back
10 → 12 Nov $2.81 to $3.01/day arena off, small front
13 Nov $6.77 arena restarted in the evening
14 → 18 Nov ≈ $22.3/day arena on to build and test the final
19 and 20 Nov $32.56 and $30.33 final, front resized up

The five days of competition and its immediate aftermath (6, 7, 8, 19 and 20 November) cost $156.65 in total. Out of the $383.88 spent on the arena, only $96.95 fall on those five days.

The rest is the arena sitting there while we built and tested: in November, 10 full days at $19.39 ($193.90), a few partial days ($8.93), plus the October test runs ($79.52 of arena time) and September's $4.54. Roughly $287 of the $384 arena line was spent outside the competition windows.

The arena's price is set by what it must hold at peak (on 17 November it carried 128 containers at rest with the 31 shared labs up), but you pay that price for every hour it is on, including the hours where you are only building images.

What actually saved money

Turning the arena off between the two phases. Between the qualifier and the final, we snapshotted and stopped the arena and shrank the front. A full day went from about $22 to about $3, which saves about $19 per day. Disks and the Elastic IP are kept, and a stop and start took about a minute. The procedure is ordinary AWS CLI:

# Generic resize / stop procedure (placeholders, not our real IDs)
export AWS_PROFILE=<profile> AWS_DEFAULT_REGION=<region>
I=<instance-id>

aws ec2 create-snapshot --volume-id <volume-id> --description "before resize"   # safety net
aws ec2 stop-instances  --instance-ids "$I" && aws ec2 wait instance-stopped --instance-ids "$I"
aws ec2 modify-instance-attribute --instance-id "$I" --instance-type Value=<new-type>
aws ec2 start-instances --instance-ids "$I" && aws ec2 wait instance-running --instance-ids "$I"
curl -sI https://<your-platform>/healthcheck | head -1

Two details matter. First, an instance without an Elastic IP gets a new public address after every stop. Our arena had none at the start and changed address on each restart until we allocated one. Second, every container must be set to restart: always and Docker must start at boot, or a resize turns into an outage.

Resizing only the component that is actually saturated. For the final we grew the front to 8 vCPU and left the arena as it was: the bottleneck during the qualifier had been the front's CPU, not the arena.

A managed model service instead of a GPU node, as described above.

Deleting everything afterwards. On 21 November, after the backups had been brought back outside AWS and checked, we deleted all infrastructure: 0 instances, 0 volumes, 0 Elastic IPs, 0 snapshots, 0 buckets by 14:45 UTC. The alternative, stopping everything and keeping it "just in case", would have cost about $15 to $20 a month in disks, snapshots and unattached IPs. The public site moved to static hosting. The order of that teardown matters more than it looks (DNS records must go before the IPs are released), and it gets its own article in this series.

What went wrong, and why

The front was undersized at launch. The qualifier opened on a 2-vCPU front. About an hour in, the load average was 6.39 and I had to resize it to 4 vCPU (a 3 to 4 minute cut, with a maintenance banner first). The next day I resized again to 8 vCPU. That second resize did not fix anything, because the real problem was a blocking lock in our own code, not capacity. That incident is another article in this series. The cost lesson: resizing is cheap on the bill, but expensive in trust when you do it in the middle of an event.

We never ran the load test. A load test with 300 simulated users and a dress rehearsal with 20 to 30 people were planned and written down. Neither was ever run. The front's size was therefore a guess, and the guess was wrong.

The day after the qualifier cost $28.22. The qualifier ended at 23:59; the arena was only stopped around 01:00 on 9 November. For a full day, everything stayed on, with the front still at its largest size. A single "end of event" checklist item would have saved most of it.

The budget alert did nothing. The monthly budget was set at $50 with a single alert at 80 %. It was exceeded and nothing happened, because a budget alerts, it does not stop anything, and an alert is only useful if someone reads it and acts. Since the teardown, the budget is set to $1/month with alerts at 80 % and 100 %, so I hear about it if anything comes back to life.

Infrastructure as code drifted. The infrastructure was created with Terraform. From 30 October on, under time pressure, every change (sizes, the arena's Elastic IP, security groups, snapshot policy) was made by hand with the CLI. By the end, the Terraform state described machines that no longer existed in that shape, and a terraform apply would have undone the live configuration. The sizes planned in Terraform were also below what the front actually needed in both phases, and below what the arena needed for the final.

The front's disk was too small. 30 GB looked plenty. With CTFd exports of several hundred megabytes, ~1 GB images and a rollback image kept after each cautious deployment, the front reached 92 % on the night before the final. Disk is one of the cheapest lines on the bill; it was a false economy.

What I would do again, and what I would change

I would keep the shape: one modest front, one big worker machine with no public entry, a free CDN plan in front, object storage for images and dumps, and a managed model service for the AI track. For around 60 teams online and 10 teams on site with 31 shared labs, a c6i.4xlarge arena was enough.

What I would change:

  1. Treat "arena on" as a budget line, not a default. Build and test images on a smaller machine, or switch the big machine on in planned windows. Most of the arena's cost was preparation time.
  2. Start the front at the size that held (8 vCPU during the competitions) and with more disk, then shrink it between phases, rather than discovering the right size live.
  3. Make the load test and the rehearsal blocking steps, and size from their numbers.
  4. Put what actually ran back into Terraform, and require an empty terraform plan before each event.
  5. Read the bill every week. Cost Explorer can be queried from the CLI. Each query is billed (our total for these calls was $0.07), so a weekly read is enough:
# Monthly usage vs. credits (Cost Explorer lives in us-east-1)
aws ce get-cost-and-usage --region us-east-1 \
  --time-period Start=2026-09-01,End=2026-11-22 --granularity MONTHLY \
  --metrics UnblendedCost --group-by Type=DIMENSION,Key=RECORD_TYPE

# Daily usage per usage type, to see which machine is burning money
aws ce get-cost-and-usage --region us-east-1 \
  --time-period Start=2026-11-01,End=2026-11-22 --granularity DAILY \
  --metrics UnblendedCost \
  --filter '{"Dimensions":{"Key":"RECORD_TYPE","Values":["Usage"]}}' \
  --group-by Type=DIMENSION,Key=USAGE_TYPE
  1. Ask early for credits, quotas and anything else that needs a human answer on the provider's side. Those answers take days or weeks. And keep a full backup outside the cloud account from day one: snapshots and buckets live in the same account as everything else.

Based on this edition, I would plan a realistic budget of $300 to $500 without credits for the same format.

Key takeaways

  • A national CTF with an online qualifier and a 24-hour on-site final cost $515.29 of AWS usage, of which $335.27 was paid after credits. That is hosting only.
  • One machine is 74.5 % of the bill: the one that runs player instances. Roughly $287 of its $384 was spent outside the competition windows.
  • Idle time is the real cost. Stopping the arena between phases took a full day from about $22 to about $3.
  • Pay-per-use services fit bursty workloads: the AI challenges cost $10.16 on Bedrock for the whole edition, against $0.615/hour for the GPU node we had planned.
  • A budget alert is not a brake. It only works if someone reads it, and the bill only stays readable if you look at it every week.

Next in the series

This was the first article of "NCTF26: running a national CTF". The next one explains how players reached their own containers through HTTPS subdomains, TLS routing and per-team WireGuard, and why a bare IP:port was never an option.

The competition is over, but the site stays up: the hall of fame, the writeups and the ideas box for the next edition are at ctf.tg. If you played, a writeup is welcome at ctf.tg/writeups.

— Ramses (hibris), technical lead, NCTF26

Next in the series: Never IP:port — per-team CTF instances with frp, WireGuard and HMAC flags

來源:DEV Community · dev.to