Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/aws-ecs-gpus/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# sst
.sst
node_modules
__pycache__
*.pyc
13 changes: 13 additions & 0 deletions examples/aws-ecs-gpus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.11-slim

WORKDIR /code

COPY requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY app.py /code/app.py

EXPOSE 8000

CMD ["fastapi", "run", "app.py", "--host", "0.0.0.0", "--port", "8000"]
34 changes: 34 additions & 0 deletions examples/aws-ecs-gpus/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pathlib import Path
import glob
import os

from fastapi import FastAPI


app = FastAPI()


def read_file(path: str):
try:
return Path(path).read_text(encoding="utf-8").strip()
except FileNotFoundError:
return None


@app.get("/health")
def health():
return {"ok": True}


@app.get("/")
def index():
return {
"message": "hello from ecs managed instances",
"gpu": {
"visibleDevicesEnv": os.getenv("NVIDIA_VISIBLE_DEVICES"),
"deviceFiles": sorted(glob.glob("/dev/nvidia*")),
"procGpus": sorted(glob.glob("/proc/driver/nvidia/gpus/*")),
"driverVersion": read_file("/proc/driver/nvidia/version"),
"cudaVersion": os.getenv("CUDA_VERSION"),
},
}
9 changes: 9 additions & 0 deletions examples/aws-ecs-gpus/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "aws-ecs-gpus",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"sst": "^4"
}
}
1 change: 1 addition & 0 deletions examples/aws-ecs-gpus/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fastapi[standard]>=0.115.0,<1.0.0
45 changes: 45 additions & 0 deletions examples/aws-ecs-gpus/sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// <reference path="./.sst/platform/config.d.ts" />

/**
* ## AWS ECS GPUs
*
* A minimal ECS service running on ECS Managed Instances with a GPU-enabled host.
* The service uses top-level `gpu`, `cpu`, `memory`, and `storage` settings, while
* the managed instances IAM resources remain customizable through `transform`.
*
* A private API Gateway HTTP API is used to test the service without exposing a public
* load balancer.
*/
export default $config({
app(input) {
return {
name: "service-gpu-example",
removal: input?.stage === "production" ? "retain" : "remove",
home: "aws",
};
},
async run() {
const vpc = new sst.aws.Vpc("MyVpc");
const cluster = new sst.aws.Cluster("MyCluster", { vpc });

// Provisions g4dn.xlarge
const service = new sst.aws.Service("MyService", {
cluster,
image: { context: "./" },
gpu: "nvidia/t4",
cpu: "4 vCPU",
memory: "10 GB",
serviceRegistry: {
port: 8000,
},
});

const api = new sst.aws.ApiGatewayV2("MyApi", { vpc });
api.routePrivate("$default", service.nodes.cloudmapService.arn);

return {
service: service.service,
api: api.url,
};
},
});
Loading
Loading