Run a ROS 2 robot stack on Amazon EC2 and drive it with a voice agent
ROS 2 development starts tethered: the robot and your laptop have to share a Wi-Fi network, the container is 14 GB, and the vision model is not a laptop workload. This post moves the whole stack onto one GPU EC2 instance, gives the robot three ways to reach it — including one that needs no internet and no vendor cloud — and puts the voice agent that drives it on Bedrock AgentCore Runtime.
Most ROS 2 development starts tethered, and it stays tethered because of three problems that all have the same root cause.
The robot and the developer's laptop have to be on the same Wi-Fi. The ROS 2 graph assumes a LAN, and the robot's WebRTC link assumes a local peer. Corporate networks with client isolation silently break it; a robot in another building is simply out of reach. Demos become "everyone please join this one access point."
The container is heavy. A realistic robot image carries ROS 2, a LiDAR pipeline, and a vision model — PyTorch wheels alone are around 600 MB, and the built image lands near 14 GB. It is also expensive to run: the object detector needs ~380 ms per frame on a CPU thread for a mid-tier backbone, and ~3900 ms for the accurate one. That is not a laptop workload.
Everyone builds it themselves. The first build takes roughly 30 minutes per developer, per laptop, and every one of them hits a different version of the same dependency problems. Onboarding a teammate means onboarding a build.
None of this is an argument against onboard compute. Plenty of robots have a programmable companion computer and run ROS 2 natively — but having an onboard processor is not the same as being allowed to deploy to it, and consumer tiers commonly expose only a vendor network API, which leaves off-board ROS 2 as the only option. Even with a capable board onboard, a 14 GB image with a vision model and a LiDAR pipeline has no business competing for a thermally-limited SoC that also has to keep the robot walking. The line to hold is latency and safety, not capability: real-time control — balance, locomotion, safety stops — stays on the robot, where it survives a network partition, while perception, mapping, planning, and model reasoning don't have to. Once they don't, the hardware they run on becomes a choice you can revisit without touching the robot.
Building the image once, pushing it to Amazon ECR, and running it on a single GPU EC2 instance solves all three. This post covers that deployment, the different ways the robot can connect to it, reaching it with no inbound network path, and hosting the voice agent that drives it on Amazon Bedrock AgentCore Runtime — so the only thing left on the laptop is a microphone.
The examples come from a working deployment with a Unitree Go2 quadruped, but nothing here is specific to that robot: any ROS 2 stack that reaches its hardware over IP fits the same shape. Everything described below — the container, the CDK stacks, and the voice agent — is available at github.com/aws-samples/sample-ros2-with-agentic-control-on-aws .

Three ways to reach the robot
The interesting design question is not where the ROS graph runs — it's who holds the radio link to the robot. There are three answers, and they suit different situations:
| Station mode | Relay mode | Access-point mode |
|---|---|---|---|
Robot's network | the same Wi-Fi as the laptop | any network with internet | the robot's own Wi-Fi hotspot, no uplink |
Where the container runs | the laptop | the cloud instance | the cloud instance |
Who owns the WebRTC link | the local container | the cloud instance | a laptop on the hotspot |
Vendor cloud involved | none — direct LAN, per-device key | yes — signaling and auth | none at all |
Operator's location | on the robot's LAN | anywhere | on the hotspot, next to the robot, on Ethernet |
ROS graph | complete, on the laptop | complete, in the cloud | a subset, injected into the cloud graph |
Cloud GPU, archiving, hosted agent | no | yes | yes |
Best for | bring-up and development; lowest latency | remote operation, autonomy, long sessions | avoiding the vendor cloud entirely; venues whose Wi-Fi the robot can't join |
Station mode is where everyone starts and what the three problems at the top of this post describe: the robot joins a normal access point, the container runs on your laptop, and the two talk directly over the LAN using a per-device key rather than any vendor service. It has the lowest latency of the three and the fewest moving parts, and it is the right choice while you are bringing a robot up. It is also the one that doesn't scale past your desk — it needs a network without client isolation, it puts a 14 GB image and a CPU-bound detector on the machine you are typing on, and nothing about it is shareable. The other two modes exist to lift that ceiling.
The two cloud modes use the same instance, the same image, and the same voice agent. They differ only in how the robot's data gets into the cloud ROS graph. Relay mode is the default; access-point mode is the fallback that works when nothing else does — and it turned out to need an inverted architecture, which is the most interesting part of this post.
The whole deployment is one box
It's worth being concrete about how little infrastructure this takes. One VPC, one instance in a public subnet at a pinned private address, a security group with a single inbound rule, an EBS volume big enough to hold the image, and an ECR repository. Nothing sits in front of the robot container, because nothing needs to: an instance is a stable address on its own, and it is a Systems Manager target on its own.
The instance sits in a public subnet on purpose — not for want of a private one — for two reasons that both matter:
- Egress through the internet gateway is free; through the NAT it's $0.045/GB — and the robot's WebRTC media plus 14 GB image pulls are the only real traffic here.
- A public-subnet instance gets a fresh public IP on every start, which is the only reliable way to shake a vendor-cloud IP block (more on that below). Behind a NAT the address is stable and a block sticks.
Pinning the private address is worth doing too. The hosted voice agent needs to reach the bridge, and a fixed
10.0.0.10 lets it hold a literal string rather than a CloudFormation import — which would otherwise become un-updatable while imported, so replacing the instance (which any user-data change does by design) would fail with "cannot update an export in use." The two stacks agree on an address, not on each other's resources.Costs land in a shape worth knowing: about $8/month while stopped (a 100 GB gp3 volume — the GPU AMI's root snapshot is 75 GiB, and the image needs the rest) and $0.526/hour while running on a
g4dn.xlarge — 4 vCPU and one NVIDIA T4, which the object detector is the entire reason for. Since the instance spends most of its life stopped, what the GPU really costs is about 44 cents per hour of actual driving.Egress for the agent's subnets is the one line item that isn't the robot's, and there are two ways to buy it: one NAT gateway at about $33/month, or interface endpoints —
ecr.api and ecr.dkr for the image pull, logs , bedrock-runtime for the speech model, and iot.data if you adopt the command bus below — which keep the traffic on AWS's network and give the agent no internet route at all. Endpoints are the better posture, since the agent talks only to AWS services and a NAT grants it unrestricted egress it has no use for. Price barely separates them: endpoints bill per Availability Zone, so five in one AZ run about $37/month, a little over the NAT, and double that across two. Decide on posture, not price.Reach an unauthenticated bridge without exposing it
foxglove_bridge is how everything else talks to the robot: it serves the ROS 2 graph over a WebSocket. It also has no authentication whatsoever, which shapes every access decision that follows.The security group allows exactly one thing inbound — port 8765 from inside the VPC CIDR — and that exists only so the hosted agent's network interfaces can reach the bridge. From a laptop there is no inbound path at all. Because the container runs with host networking the bridge lands on the instance's own port 8765, and the instance is itself a Session Manager target, so the whole access path is one hop:
aws ssm start-session \ --region us-east-1 \ --target "$INSTANCE_ID" \ --document-name AWS-StartPortForwardingSession \ --parameters '{"portNumber":["8765"],"localPortNumber":["9876"]}'Leave that running and the bridge is on
ws://localhost:9876 . Point Lichtblick (or Foxglove) at it as a Foxglove WebSocket connection, or point the voice agent at it with ROS_BRIDGE_HOST=localhost ROS_BRIDGE_PORT=9876 . No SSH key, no open port, no public DNS. Authorization is entirely "who can start an SSM session" — an IAM question, with every session in CloudTrail.There is a throughput cost to that convenience: SSM relays every byte through the service, and the camera and point-cloud topics feel it. The faster option is a direct TCP connection to 8765 on the public IP, which needs an ingress rule for the operator's address — and that rule is deliberately not in the template. A small script adds it as a single-host
/32 at the start of a session and revokes it on stop, so exposure is bounded by the session rather than by however long someone forgets to redeploy.Be clear-eyed about what that rule means while it exists: the bridge has no authentication, so anything at that address can publish to the command topics — that is, drive the robot. And a
/32 is only as narrow as the address is; behind a corporate NAT it covers every host sharing that egress. The SSM tunnel has no such exposure, which is why it stays the default.Relay mode: the cloud holds the robot link
In the default mode the robot connects to the vendor's TURN server and the container in the cloud connects to the same relay, so the two never need to share a network. The robot needs internet; that's the whole requirement. This is the mode that gets you a complete ROS graph in the cloud — every topic, plus SLAM and navigation — and an operator who can be anywhere.
The cost is a dependency on someone else's cloud for signaling and authentication, and it bites in a specific way.
Expect the link to drop, and be careful how you retry
A relayed WebRTC connection is not a stable pipe. The peer connection drops periodically and the driver has to reconnect on its own — but how it retries matters more than that it retries.
Naive reconnection re-authenticates every time, because constructing the connection object with a username and password performs a fresh login. At a 15-second retry interval, a robot that is simply powered off produces around 240 password logins per hour from one IP address — which the vendor's edge (Tencent EdgeOne, here) correctly reads as abuse and WAF-blocks. After that, every request from that IP fails, including unauthenticated ones. Two fixes:
- Cache the access token across reconnects and hand it to the library directly, so a reconnect is not a login. Re-authenticate only when the token stops working.
- Classify the failure and back off differently. A dropped data channel deserves a retry in about a second. A cloud rejection deserves 300. Detecting the second case is fiddly, because the block arrives in two shapes: an HTTP 567 status, and — once the edge decides to serve a challenge page instead — a 2xx whose body is HTML, which surfaces in your code as a JSON decode error. Both mean the same thing: stop knocking. Log it once, cap the backoff, and let the block age out instead of refreshing it with your own traffic.
This is where that fresh-public-IP-per-start property earns its keep: a stop/start is the one reliable way to clear a block that has already landed.
Recover the video, not just the connection
Over a relayed path the H.264 decoder frequently starts mid-GOP and stays stuck on "failed to decode" until the robot happens to emit a keyframe, which can take a long time — the feed is just black. The fix is to ask for one: send an RTCP Picture Loss Indication as soon as the video track opens, repeat every second until the first frame actually decodes, then stop. Recovery drops from tens of seconds to about one.
Access-point mode: the laptop holds the robot link
The point of this mode is to take the vendor's cloud out of the path entirely. Relay mode depends on it for signaling and authentication, which means an outage or an IP block on someone else's edge is an outage for you — and as the previous section describes, that is a failure you can trigger yourself. Every robot of this class can fall back to being its own access point: a Wi-Fi hotspot at a fixed address with no uplink at all. No signaling server, no login, no WAF to get blocked by, and nothing between you and the robot but a radio.
There's a second, more mundane reason it comes up, and it will be familiar to anyone who has demoed in a hotel or a conference centre. Guest Wi-Fi at public venues usually sits behind a captive portal — you join the network, a browser opens, and you accept terms or type a room number. The robot's provisioning app takes an SSID and a password and nothing else. It has no browser and no way to complete that second step, so the robot simply cannot join the network, no matter how good the signal is. Relay mode is unavailable not because the venue lacks internet but because the robot can't authenticate to it. Its own hotspot has no such problem.
The obvious implementation is to point the cloud container at the robot's hotspot address. It cannot work, and the reason is instructive.
On the local path the WebRTC library builds its configuration with no ICE servers, so both peers offer only host candidates. The cloud instance's
10.x address is simply unreachable from a robot that is its own gateway with no uplink — there is no route and nothing to relay through. Adding a TURN server on the laptop fixes the routing on paper, but a relay has to accept unsolicited inbound traffic, and on a managed laptop the corporate packet filter drops exactly that. The failure is visible at the interface level: the cloud's packets arrive on the tunnel interface (input counters climb) and the OS answers none of them (output counters stay flat).So invert it. Make every connection laptop-initiated, which is what the packet filter permits:

The mechanism that makes this more than a viewer is a
foxglove_bridge feature worth knowing about: a WebSocket client that advertises topics gets real ROS publishers created for them. So the laptop bridge isn't visualizing the robot's data — it is publishing it into the cloud ROS graph, where ordinary ROS nodes consume it. The same socket carries the command topics back the other way, and the bridge forwards them to the robot over the WebRTC data channel it already holds.Three things to get right:
- Stop the container from fighting for the robot. The robot accepts one WebRTC client at a time. Run the container with its connection type set to a value its driver doesn't recognize as a real transport, and it skips connecting and skips its reconnect watchdog while still serving the full ROS graph and keeping the command topics present.
- The laptop needs a wired connection. Its Wi-Fi is spent — it has to be joined to the robot's hotspot for the radio link — and the hotspot has no uplink, so the route to AWS has to come from somewhere else. In practice that means Ethernet (a USB-C adapter, if the laptop has no port), and it is a hard requirement rather than a nicety: without a second interface there is no tunnel, and without the tunnel the robot's data has nowhere to go. Plan for it when you plan the venue — this is the mode for rooms where the Wi-Fi is unusable, which are often rooms where a spare Ethernet drop takes some finding.
- Send compressed frames. This link crosses the internet twice, so raw images are out of the question; the bridge publishes the compressed camera topic and point clouds are optional and capped.
What you give up is real: it is a subset of the graph. Camera, robot state, battery, point cloud, and transforms go up; odometry, joint states, SLAM, and navigation don't. Autonomy stays in relay mode. What you keep is everything the cloud was for — the GPU detector, video archiving, and the hosted voice agent all consume ROS topics, and those topics are now present regardless of how they got there.
Make video survive the link
Video needs two different answers, in either mode.
The interactive feed. A camera publishing raw
sensor_msgs/Image at 15 fps is about 0.69 MB per frame — roughly 10 MB/s. Neither a port-forwarded WebSocket nor a laptop-to-cloud bridge can sustain that. Frames queue, latency climbs into the seconds, and the viewer is useless for driving.The fix is a small republisher node that subscribes to the raw image topics and publishes JPEG
sensor_msgs/CompressedImage alongside them. At quality 50 a frame drops from ~690 KB to ~24 KB — a ~29x reduction — which fits comfortably at full frame rate, and both Lichtblick and Foxglove decode JPEG natively. Subscribe to /camera/image_raw/compressed instead of /camera/image_raw .Two details make or break that node. Match subscription QoS per source: the camera driver publishes
BEST_EFFORT while the detector publishes RELIABLE , and a mismatch delivers no frames at all, silently — it looks like a broken topic, not a config error. And publish the compressed output as BEST_EFFORT , depth 1, which is how the Foxglove bridge subscribes to image topics anyway.The recorded feed. Continuous video shouldn't cross an operator's tunnel at all. A producer node batches frames, encodes them with ffmpeg, and
PutMedia s them to Amazon Kinesis Video Streams:-c:v libx264 -preset veryfast -tune zerolatency -profile:v baseline-g <fps> -bf 0 -b:v 2000k -f matroska -cluster_time_limit 500Zero-latency tuning, no B-frames, a keyframe every second, and 500 ms MKV clusters. That last flag is the latency knob: KVS fragments on cluster boundaries, so cluster size sets how quickly playback catches up. Dropping the upload chunk from 10 seconds to 2 trims the rest. Watching it is then an IAM question too — the KVS console's live playback, with no stream URL to share.
Stream the annotated topic rather than the raw one. Bounding boxes get drawn once, on the robot's stack, and every consumer — the live viewer, the archive, anything you add later — sees the same overlay.
Keep SLAM inside the CPU budget
Even with a GPU doing perception, 2D SLAM runs on the CPU, and starvation there produces a confusing symptom: the map freezes or duplicates itself mid-run while every node still looks healthy. A LiDAR accumulation node that sorts its entire point set on every frame will saturate a core at its default one-million-point cap, and the
/scan topic that SLAM actually consumes stops being published. Three changes fixed it: cap accumulation at 60,000 points; point the point-cloud-to-laser-scan converter at that capped cloud rather than the filtered topic that sums hundreds of clouds together; and turn off the 3D point-cloud dump while mapping, since it re-serializes the whole accumulated cloud every cycle and 2D SLAM never reads it.The lesson transfers to any ROS 2 stack in a container with a fixed vCPU allocation: the node that starves is rarely the node that's slow.
How the agent — and the bridge — reach ROS 2
The voice agent is a plain Python process: no ROS 2 installation, no DDS, no rclpy. It speaks the Foxglove WebSocket protocol directly, which is what lets it run on a laptop, in a small container, or on a hosted runtime without dragging a ROS distribution along. Its image contains no ROS 2 at all. The access-point bridge is the same trick pointed the other way — publishing instead of subscribing — which is why one protocol implementation serves both.
That's worth spelling out because it's a common trap:
foxglove_bridge is not rosbridge_websocket . It speaks a binary protocol (subprotocol foxglove.sdk.v1 ), not JSON, so roslibpy will not work against it. Frames are [opcode][channel u32 LE][CDR payload] , and the payload is ROS 2's own wire encoding — XCDR1 little-endian, a 4-byte representation header, each field aligned to its own size, strings as a length-with-null prefix. Implementing enough of that to publish a Twist and parse a state message is maybe 150 lines, and in exchange nothing outside the container needs a ROS dependency.On top of that transport, each agent tool maps onto a topic:
Tool intent | ROS 2 mechanism |
|---|---|
Move / turn | publish geometry_msgs/Twist to /cmd_vel_out at ~10 Hz |
Posture, tricks, stand up | publish a vendor request message to /webrtc_req ( api_id + JSON parameter) |
Battery, pose, state | subscribe to the robot state topics |
The 10 Hz republish is not decoration — the robot's own watchdog expires if commands stop arriving, so "walk forward for two seconds" is a timed publish loop rather than a single message.
One more design choice pays off repeatedly: give the WebSocket client and the direct-WebRTC client the same public method surface, and have the entry point install one at startup. The tools then don't know or care which transport is underneath, which is what makes the same agent work in both connection modes without a line of change.
A fourth transport, and the constraint it removes
That shared surface earns its keep when you notice what every transport so far has in common: the agent process must be able to reach the robot. That is the assumption behind the SSM tunnel, the security-group rule on 8765, and a fair amount of networking effort.
So invert it. Put a small process next to the robot that subscribes to an AWS IoT Core topic, and give the agent a client that publishes to it and waits for the reply on a topic of its own. The robot host dials out; nothing reaches inward. No tunnel, no inbound rule, and a dropped link just queues. Because the new client implements the same method surface, the tool layer needed no changes at all — the entry point picks a transport from an environment variable and the agent is none the wiser.
Two details are worth copying. First, keep the closed-loop behaviours — visual tracking, greeting a visitor, searching for an object — on the robot side of the bus. They servo against fresh camera frames, and a round trip through AWS per correction would ruin them; with dispatch by method name they run next to the robot for free. Second, dispatching a method name off a wire payload is remote code execution unless you allowlist it, so allowlist it.
Ask what the robot sees, and what it saw
Because the compressed camera topic is on the bridge in either mode, visual question answering needs no extra infrastructure. A
describe_scene tool grabs the latest frame, sends it to a multimodal model on Amazon Bedrock, and returns the text to the speech model so it answers in its own voice — no separate text-to-speech step. Latency is low enough to feel conversational.The interesting part is what happens next. Every call snapshots a timestamped (image, description) pair into a rolling in-memory log — a couple of hundred frames. That turns two more tools on:
-
recall_scene— "what was on the table 30 seconds ago?" Finds the snapshot nearest the requested time and answers from that image.
-
compare_scenes— "what changed?" Sends the past snapshot and a live frame to the model together and reports the difference.
Cheap to build — a rolling list and two extra tool definitions — and it gives the robot something that reads as memory. It is also strictly bounded: the log lives in the agent process, so it is per-session and gone when the session ends.
Which is why the same two questions also exist against the recorded stream. A second pair of tools invokes a Lambda function that pulls the relevant fragments out of KVS, sends them to Bedrock, and returns the answer. The tool surface is nearly identical; what differs is the memory substrate:
| Live-frame tools | Recorded-stream tools |
|---|---|---|
Source | latest frame off the bridge | fragments retrieved from KVS |
Memory | in the agent process | the durable video archive |
Reach | this session only | as far back as the stream retains |
Survives an agent restart | no | yes |
Latency | conversational | slower — fragment retrieval, then the model |
Neither replaces the other. The live tools are what you want mid-conversation; the recorded ones answer questions about a shift that ended before the current session began, which is the version that matters once more than one person is operating the robot.
Move the agent into the cloud too
At this point the robot's compute is in the cloud and the agent is still a process on a laptop. The agent is an Amazon Nova Sonic speech-to-speech model with a set of Strands Agents tools (
stand_up , move , describe_scene , …). Nothing about it is inherently local except the audio devices.Bedrock AgentCore Runtime hosts it VPC-attached, in the same VPC as the robot container, pointed straight at that pinned private address. The laptop client shrinks to microphone capture and audio playback over a SigV4 pre-signed WebSocket to the runtime — no endpoint of our own, IAM as the front door. And because the agent consumes ROS topics rather than the robot directly, it works unchanged in access-point mode: the topics are there either way.
Gate the microphone
A speech-to-speech agent with an always-open microphone is a liability anywhere real. On a conference floor or a busy lab, background conversation becomes commands, and a robot that moves for real should not take instructions from the room. Give the operator an explicit push-to-talk: the mic streams only between an on and an off, and the client prints when it is live.
The subtlety is that you cannot implement that by simply stopping the audio stream. Speech-to-speech models infer end-of-utterance from trailing silence, so a stalled stream leaves the turn open — the command appears to do nothing until the next time someone speaks, and transcripts run together. Send frames of digital silence while the mic is off. The stream never stalls, the model closes turns normally, and the room is inaudible. (The same trick makes a text-only mode work: no mic at all, silence throughout.)
Pair it with barge-in. The server signals an interruption when the operator talks over a reply, and the client drops its buffered playback immediately rather than finishing a sentence nobody is listening to.
Two operational details worth copying
Keep one shared robot client per process, not one per session. The bridge subscriptions are the expensive part, and tearing them down when an operator's WebSocket closes makes the next session slow and lossy.
Roll new images without replacing the instance. Anything that changes user data replaces the instance, which throws away the cached image layers and buys back the cold 14 GB pull you moved to a persistent volume to avoid. So the routine path for a new build is to pull and restart the unit in place over SSM — seconds, cache intact, no stack update. Reserve template changes for actual infrastructure changes. (Watch for AMI aliases that resolve to
latest , too: a deploy that picks up a newly published AMI id replaces the instance for you.)Stop the instance when nobody is driving
Stopping the instance is the whole cost-control story: compute billing ends, the volume and its cached layers persist, and the next start is back to about 40 seconds. There's no service to scale and no capacity to drain —
stop-instances , and later start-instances , with the systemd unit bringing the robot back on boot.The less obvious reason to do it is the retry behavior above: an instance left running while the robot is switched off is a reconnect loop pointed at the vendor's cloud. The systemd start limit is a backstop, not a substitute.
For everything you'd otherwise SSH in for, Session Manager covers it — a shell on the host,
send-command for one-off checks like systemctl is-active , docker ps , or journalctl -u go2 , and the CloudWatch log group for container output. The instance never needs an open port for any of it.The result: one 14 GB image built once instead of on every laptop, a GPU the robot could never carry, two independent ways for the robot to reach it — one that works from anywhere and one that works with no internet at all — and a voice agent that doesn't know or care which one you're using.
Try it
The complete sample — Dockerfile, CDK stacks for the network, instance, and AgentCore runtime, the voice agent, and the transports described above — is on GitHub:
Start with
AWS_DEPLOYMENT.md for the deployment walkthrough. Issues and pull requests are welcome.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article