Running an SSH server on AWS RoboMaker

Learn how to configure and run an OpenSSH server within an AWS RoboMaker simulation job container, enabling remote shell access for real-time inspection and troubleshooting.
Running an SSH server on AWS RoboMaker
Overview
AWS RoboMaker is a fully managed service that enables Robotics developers to build, run, scale, and automate simulations without managing any infrastructure. During the development cycle, roboticists frequently need to perform a deeper inspection of what is going on within the running container. Though CloudWatch offers important metrics and logs related to simulation jobs, you still need to rely on traditional methods to login to the running container and inspect the real-time status of running processes (ROS nodes), messages and application logs. In this tutorial, you will learn the steps needed to configure SSH login to a running container on a AWS RoboMaker simulation job. SSH will provide remote shell access into a running container, which can be beneficial to inspect and troubleshoot logs and configurations. This tutorial will go over how to install and run OpenSSH on AWS RoboMaker. You will configure the required security groups and network parameter settings to enable SSH login to the container.
Prerequisites
A basic understanding of Docker is required, as this tutorial involves building a Docker image in an Ubuntu 20.04 environment. You need an AWS account with the necessary AWS IAM permissions to create an AWS Cloud9 development environment, create and push a container to an Amazon Elastic Container Registry, create an AWS RoboMaker simulation application, and run an AWS RoboMaker simulation job. Finally, this tutorial can incur costs, so follow the clean step at the end of the tutorial to avoid any surcharges.
Solution Overview
In this tutorial, you will create resources in your AWS account using a command line API. You can set up a development environment with the AWS CLI installed or create an AWS Cloud9 environment. We will use the following process to demonstrate this solution:
- Generate an SSH Key Pair on Cloud9.
- Build a Docker image with OpenSSH.
- Push the Docker image to the Elastic Container Registry (ECR).
- Configure and run a simulation job in AWS RoboMaker.
- SSH into the Docker container.
Generate an SSH Key Pair on Cloud9
- Use these steps to setup the Cloud9 environment.
- Connect to the Cloud9 environment. Run the following command to create a new folder
robomaker-sshdemo
.mkdir robomaker-sshdemo
-
Run the following command in the Cloud9 terminal to generate an SSH key.
ssh-keygen -t rsa -b 4096 -
Follow the instructions on the command prompt and enter the complete location of the key file. For this tutorial, we will enter the directory location of
robomaker-sshdemo
created earlier./home/ec2-user/environment/robomaker-sshdemo/id_rsa
Once the public and private keys are generated, we will use the public key during OpenSSH deployment in the container. The private key must be kept securely on your machine and used to provide SSH access.
Build docker image with OpenSSH
- Create a Dockerfile inside the
robomaker-sshdemo
directory and add the following content.#SSH access to the running container on AWS RoboMaker FROM osrf/ros:humble-desktop-full RUN apt update && apt install -y openssh-server xterm vim sudo RUN groupadd sshgroup && useradd -ms /bin/bash -g sshgroup sshuser && usermod -aG sudo sshuser RUN mkdir -p /home/sshuser/.ssh COPY id_rsa.pub /home/sshuser/.ssh/authorized_keys RUN chown sshuser:sshgroup /home/sshuser/.ssh/authorized_keys && chmod 600 /home/sshuser/.ssh/authorized_keys RUN sed -i 's/#Port 22/Port 1122/' /etc/ssh/sshd_config ENTRYPOINT ["/bin/bash", "-c"]
- Run the Docker build command to build the image.
sudo docker build -t sshdemo:latest .
Once the Docker image is created, proceed with the next step.
Push Docker image to Elastic Container Registry (ECR)
In this step, we create an ECR repository to store Docker image.
-
Run the following command to create an ECR repository on your AWS account.
aws ecr create-repository --repository-name sshdemo -
Go to the ECR console inside your AWS account and search for the
sshdemo
repository. ChooseView push command. - Copy and run the firstcommand to retrieve an authentication token and authenticate your Docker client to your registry. - Copy and run the thirdcommand to tag the Docker image so you can push the image to this repository. - Copy and run the fourthcommand to push this image to your newly created AWS repository.
This will take less than 5 minutes to push the Docker image to your ECR repository. You can review the most recent image in the sshdemo
repository. Once completed, proceed to the next step.
Configure and run simulation job on AWS Robomaker
In this step, you will create a AWS RoboMaker simulation job with the sshdemo Docker image.
- Navigate to the
AWS RoboMakerservice. On the left navigation, selectSimulation applicationsunder theDevelopmentmenu. ChooseCreate simulation application. - Enter
sshdemo
in theNamefield. - Choose
Browse ECR. ForAmazon ECR repository, choosesshdemo
. - Choose
Create. - From the left navigation menu, select
Simulation jobsand chooseCreate simulation job. - For the
IAM role, chooseCreate new roleand enter the new IAM role name assshdemo
. - For
VPCunderNetworking, choose thedefault VPC. - For
Security groups, choose thedefault security group. The Dockerfile uses 1122 to run an SSH server. Ensure port 1122 is open for inbound communication for the default security group. For more details on how to add rules to a security group, follow the link. - For
Subnets, choose any two subnets. - Set
Assigned public IPtoYesand chooseNext. - Under
Specify robot application, chooseNoneunderChoose methodand chooseNext. - Under
Specify simulation application, selectexisting applicationsunderChoose method.ForSimulation application, choosesshdemo
. - Under
Launch commandenter the following command.source /opt/ros/humble/setup.bash && ros2 run demo_nodes_cpp talker
- Expand the
Simulation application toolssection and chooseCustomize tools. ChooseAdd tooland input the indicated information for the following fields:Tool name:
Exploratory-xterm
Command:/usr/bin/xterm -geometry 120x40
- Choose
Restart
from theExit behaviordrop-down - Choose
Enable UI Streaming
forOutput settings - Make sure the Send output to Amazon CloudWatchcheckbox is chosen - Choose Add tool
-
Under Simulation application connectivityenter the following details.- Simulation job port:
1122 -
Application port:
1122 -
Port type:
Public -
Simulation job port:
-
Choose Nextand chooseCreateto create the simulation job.
This will take around 5 minutes to create the simulation job. Please move forward to the next step once the job is in the RUNNING
state.
SSH into the docker container
In this step, you will SSH to the container running on the AWS Robomaker.
- Go to the
Simulation application tools,chooseConnectunder the
Exploratory-xterm
tool, and execute the following command to start the SSH server.source /opt/ros/humble/setup.bash ros2 topic list service ssh restart
-
Reset the password for sshuser.
passwd sshuser -
Go to the running simulation job and copy Public IPaddress under theNetworking section. - Open the local terminal and navigate to the private key location.
-
Run the following command to ssh into the container.
ssh -i id_rsa sshuser@<<Public IP>> -p 1122 -
Elevate the privilege and run the following commands in the SSH terminal to return a list of all the topics.
sudo -i source /opt/ros/humble/setup.bash ros2 topic list -
Run the following command to see the data being published on a topic.
ros2 topic echo /chatter
Congratulations! You can SSH into the container running on AWS Robomaker. You can run the top
command to see running processes and navigate the directories to expl
Source: AWS Robotics Blog















