Deploy YOLOv9 to AWS EC2

Set up an EC2 instance, run YOLOv9 on images and video with Roboflow Inference, and build it into a Workflow.

Overview

To deploy a YOLOv9 model to AWS EC2, you will:

  1. Set up an EC2 instance and start the Inference Server
  2. Run a pretrained RF-DETR model to check the setup
  3. Get your YOLOv9 model's ID from Roboflow
  4. Run your model on an image
  5. Run your model on video
  6. Run a Workflow that uses your model
  7. Deploy with a coding agent

Step 1: Set Up an EC2 Instance

The quickest route is the Inference CLI's cloud command. It uses SkyPilot (opens in a new tab) to launch a GPU instance in your AWS account with the Inference Server already running. Connect SkyPilot to your AWS account first (SkyPilot's cloud setup (opens in a new tab)), then run this on your own computer:

Shell
pip install inference "skypilot[aws]"
inference cloud deploy --provider aws --compute-type gpu

When it finishes, it prints the server's address, such as http://34.66.116.66:9001. Use that address as api_url in the code on this page. inference cloud status lists your deployments, and inference cloud undeploy shuts one down so it stops billing.

To use an instance you manage yourself instead, launch a GPU instance (a g4dn.xlarge with an NVIDIA T4 runs most models) from an AWS Deep Learning Base GPU AMI, which comes with the NVIDIA driver, Docker and the NVIDIA Container Toolkit, then SSH in and start the server on all of the instance's network interfaces:

Shell
pip install inference-cli
inference server start --bind-address 0.0.0.0

Then add an inbound rule to the instance's security group: Custom TCP, port 9001, with your own IP address as the source. The server has no authentication by default, so never open the port to the whole internet (securing a self-hosted server (opens in a new tab)).

Step 2: Run RF-DETR on Your Device

Check the setup with RF-DETR trained on the Microsoft COCO dataset (opens in a new tab), which detects 80 everyday objects. Install the client libraries on the machine that calls the server:

Shell
pip install inference-sdk supervision pillow

Set the ROBOFLOW_API_KEY environment variable to your Roboflow API key (opens in a new tab) first. Run the code on your own computer with api_url set to your server's address, or on the server itself with http://localhost:9001. Then run:

Python
import os

from inference_sdk import InferenceHTTPClient
from PIL import Image
import supervision as sv

client = InferenceHTTPClient(
    api_url="http://YOUR_SERVER_IP:9001",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)

image = Image.open("image.jpg")
results = client.infer(image, model_id="rfdetr-small")

detections = sv.Detections.from_inference(results)
annotated = sv.BoxAnnotator().annotate(scene=image.copy(), detections=detections)
annotated = sv.LabelAnnotator().annotate(scene=annotated, detections=detections)
annotated.save("annotated.jpg")

The first request downloads the model weights, so it takes longer than the ones after. annotated.jpg shows what RF-DETR found.

Step 3: Use Your YOLOv9 Model

Roboflow no longer accepts new YOLOv9 weight uploads. A YOLOv9 model you uploaded before, or trained in Roboflow, still deploys with the steps below. For a new model, train one in Roboflow (RF-DETR and YOLO26 both train there), or train YOLO26 yourself and upload its weights (Upload Custom Weights (opens in a new tab)).

You need the model's project ID and version number for the next step (where to find them (opens in a new tab)).

Step 4: Run Your Model on an Image

Point the same code at your own model by its project ID and version:

Python
import os

from inference_sdk import InferenceHTTPClient
from PIL import Image
import supervision as sv

client = InferenceHTTPClient(
    api_url="http://YOUR_SERVER_IP:9001",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)

image = Image.open("image.jpg")
results = client.infer(image, model_id="YOUR_PROJECT_ID/1")

detections = sv.Detections.from_inference(results)
annotated = sv.BoxAnnotator().annotate(scene=image.copy(), detections=detections)
annotated = sv.LabelAnnotator().annotate(scene=annotated, detections=detections)
annotated.save("annotated.jpg")

sv.Detections.from_inference turns the response into detections you can count, filter, track or draw with supervision (opens in a new tab).

Step 5: Run Your Model on Video

Stream video to the server with the WebRTC client, which keeps one session open instead of sending a request per frame:

Shell
pip install "inference-sdk[webrtc]"
Python
import os

from inference_sdk import InferenceHTTPClient
from inference_sdk.webrtc import VideoFileSource
import supervision as sv

client = InferenceHTTPClient(
    api_url="http://YOUR_SERVER_IP:9001",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)

session = client.webrtc.stream(
    source=VideoFileSource("video.mp4"),
    model_id="YOUR_PROJECT_ID/1",
)

@session.on_frame
def on_frame(frame, data):
    if data is None:
        return
    detections = sv.Detections.from_inference(data)
    print(f"{len(detections)} objects in frame")

session.run()

VideoFileSource reads a file. Use WebcamSource() for a camera on the machine running the script, or RTSPSource("rtsp://...") for a network camera the server can reach.

Step 6: Run a Workflow

A Workflow chains models with the logic around them, such as counting, tracking, filtering by zone or sending results to your own systems, and runs on your EC2 instance like a single model does. Build one in the Roboflow app with your model in it, then run it by its workspace and Workflow ID:

Python
import os

from inference_sdk import InferenceHTTPClient

client = InferenceHTTPClient(
    api_url="http://YOUR_SERVER_IP:9001",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)

result = client.run_workflow(
    workspace_name="YOUR_WORKSPACE",
    workflow_id="YOUR_WORKFLOW_ID",
    images={"image": "image.jpg"},
)
print(result[0])

The result has one entry per image, holding every output the Workflow defines. To run the Workflow on video, pass workflow and workspace to client.webrtc.stream() in place of model_id (video with Workflows (opens in a new tab)). See Deploy a Workflow (opens in a new tab) for the other ways to run one.

Step 7: Deploy with a Coding Agent

The Roboflow MCP server (opens in a new tab) gives a coding agent such as Claude Code or Cursor access to your Roboflow workspace. It can list your models, run one on a test image, build and run a Workflow, and write the deployment code for your EC2 instance. Add it to Claude Code:

Shell
claude mcp add -s user roboflow --transport http https://mcp.roboflow.com/mcp

The first time the agent uses it, you sign in to Roboflow in your browser. In Cursor, add https://mcp.roboflow.com/mcp under mcpServers in ~/.cursor/mcp.json. Then ask the agent, for example: "Deploy my YOLOv9 model to AWS EC2 with Roboflow Inference and write a script that runs it on my camera stream."

Start where you are

Speak with an AI expert

Our team will help you start solving business problems on the first call.

  • Solution architecting
  • Live demonstration
  • Pricing and specifications
  • Feasibility assessment

Over 80,000 organizations build with Roboflow.

Rivian
Pella
Chobani
USG Corporation
BNSF Railway
American Woodmark
Outcomes
Patrick Industries
Peer Robotics