AWS Builder Center
An AI Hunter, a WebSocket, and Amazon ECS Express Mode

An AI Hunter, a WebSocket, and Amazon ECS Express Mode

An AI hunter chases players in real time on ECS Express Mode. BFS handles movement, Bedrock picks strategy every few seconds, WebSocket works with zero extra config

Cloud Engineer
I wanted to try Amazon ECS Express Mode for something less serious than a web API, so I built a chase game: a single AI hunter, running inside a Fargate container, tracking down every player connected over WebSocket. If it catches everyone before the clock runs out, it wins.
The premise only works if the hunter feels like it's actually thinking, not just walking toward the nearest dot on a grid. So the hunter runs on two layers. Movement, every 200ms, comes from a plain BFS shortest-path search toward whatever target it's currently been assigned. Every 2.5 seconds, a separate call goes out to Bedrock (Haiku 4.5) with the current board state, and the model picks one of three modes:
"hunt" - beeline for the closest player
"ambush" - head toward where the closest player is likely going, not where they are
"lone_wolf" - target whichever player is farthest from everyone else

The model also returns a one-line taunt, which shows up on screen right as the mode changes. Splitting it this way means the hunter never waits on a model call to take its next step, movement stays smooth at 5 ticks per second, and the "thinking" only has to keep up with a 2.5-second cadence instead of a 200ms one. A slow or failed Bedrock call just falls back to  "hunt"  and the game keeps running.

Why ECS Express Mode specifically

A chase game needs a persistent connection so the server can push hunter positions to every player without them polling for it. That rules out a lot of the usual serverless defaults. Express Mode turned out to fit well: point it at a container image, and it provisions a Fargate service, an Application Load Balancer with TLS, security groups, and auto scaling, all from three inputs, an image, an execution role, and an infrastructure role. WebSocket traffic (the  Upgrade  header) went through the auto-configured ALB with no special handling on my end.
The whole app is one Node.js process using the  ws  library, serving both the WebSocket endpoint and the static Canvas frontend. One Dockerfile, no separate frontend host:
FROM public.ecr.aws/docker/library/node:22-bookworm-slim
WORKDIR /app
COPY package.json ./
RUN npm install --omit=dev
COPY . .
EXPOSE 8080
CMD ["node", "server.js"]
Creating the service itself is one CLI call once the image is in ECR:
aws ecs create-express-gateway-service \
--service-name hide-from-the-agent \
--infrastructure-role-arn "$INFRA_ROLE_ARN" \
--execution-role-arn "$EXEC_ROLE_ARN" \
--task-role-arn "$TASK_ROLE_ARN" \
--health-check-path "/healthz" \
--primary-container "image=${REPO_URI}:latest,containerPort=8080" \
--cpu 256 --memory 512
That command returned a working HTTPS URL in about a minute.

Two things that broke on the way

The first was IAM, and it cost more time than it should have. I gave the task role  bedrock:InvokeModel  scoped to the Haiku model's ARN in  us-east-1 , since that's the region I call. The calls still failed with  AccessDenied , on a resource ARN in  us-east-2 . Cross-region inference profiles (the  us.anthropic...  model IDs) route the actual request to whichever region has capacity, and the IAM check happens against that region's foundation-model ARN, not the one you dialed. The fix was widening the resource to a region wildcard:
"Resource": "arn:aws:bedrock:*::foundation-model/anthropic.claude-haiku-4-5-20251001-v1:0"
The second was local, not AWS: my Docker setup (Colima) had no  buildx  installed, so  docker build --platform linux/amd64  silently produced an image that Fargate's task launch rejected as the wrong platform.  brew install docker-buildx , then  docker buildx build --platform linux/amd64 --push , and the image ran.

What it's like to play

The BFS-only baseline was frustrating in a boring way, you could always tell exactly what the hunter would do next. Once the mode-switching landed, that predictability broke in a good way: a hunter that suddenly gives up on the player right next to it to cut off someone three corridors away feels like a decision, even though the pathfinding underneath is the same shortest-path search the whole time. Most of what reads as "smart" here is a cheap trick, changing the target function every couple of seconds is far less work than it looks like from the outside. That's roughly the whole idea of splitting movement from strategy: the expensive part only has to be right often enough to be surprising.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article