AutomateWorkflows
All articles
Oct 1, 20268 min read

Deploying a Trading Bot on AWS EC2 with Docker: A Practical Overview

Running a bot on your laptop is a prototype. Running it on a cloud server with Docker, systemd and logs is a system. Here's what the move looks like.

AWSDockerDeploymentDevOps

A trading bot that runs on your laptop is a toy. Close the lid, lose Wi-Fi, let the OS reboot for an update — and your positions are naked. Any strategy you take seriously eventually needs to live somewhere that stays up. For most retail traders, that somewhere is a small cloud server running Docker. This article walks through what the move looks like at a high level — the full build is a project in the course.

Why EC2, and why Docker

AWS EC2 gives you a Linux box with a predictable IP, bulletproof uptime and billing you can control. A t3.micro or t4g.nano costs a few dollars a month and is plenty for a single-process trading bot. Docker gives you a reproducible environment: your bot runs the same way on the server as it does on your laptop, with the same Python version and the same dependencies. No more 'works on my machine'.

The deployment shape

  • Write a Dockerfile that pins your Python version, installs requirements and copies in your bot code.
  • Build the image locally, push it to a container registry (ECR, Docker Hub, or just rebuild on the server).
  • SSH into your EC2 instance, pull the image, run it as a container.
  • Wrap the container in a systemd service so it starts on boot and restarts on crash.
  • Pipe logs to disk — and ideally to CloudWatch or a log aggregator — so you can debug after the fact.

The parts beginners skip

A bot in production is not just a running process. The questions that matter are not 'is it running' but 'will I know when it stops' and 'can I shut it down cleanly if it misbehaves'. That means:

  • Health checks: the bot pings a status endpoint or writes a heartbeat file every few seconds.
  • Dead-man alerts: if the heartbeat stops, you get a Telegram or email alert within minutes.
  • Graceful shutdown: SIGTERM is handled, open orders are cancelled, positions are closed cleanly.
  • Secrets management: API keys live in environment variables or AWS SSM, not in the Docker image.
  • Kill switch: a way to stop trading immediately without needing SSH access.

Costs, roughly

For a single Python bot running one strategy, the realistic monthly bill is small. A t4g.nano or t3.micro, basic storage, modest data transfer — expect to spend less than the price of a dinner. AWS free tier covers the first year for most of this if you're starting fresh.

Deployment is the moment code becomes a system. Everything that was optional on your laptop is now mandatory.

The takeaway

Moving from a laptop script to a Dockerized bot on EC2 is the single biggest reliability jump you can make. The strategy stays the same; the surface area for human error shrinks dramatically. If you only automate one thing after writing your first bot, automate the deployment pipeline — because the goal is not to run a bot once, it's to run it every day without thinking about it.

Workshop

Build the real thing.

Articles help with the ideas. The live workshop walks you through building, backtesting and deploying a bot end-to-end.

Join the workshop