DEV Community

Didy
Didy

Posted on

Setup Remote Dev Environment (memo)

Setup

This article is a memo summarizing the steps I followed to set up a remote dev environment on AWS EC2.

First, create a VPC and enable the "Auto assign public IPv4 address" option.

Next, create a security group. Set up the port and IP address for SSH access.

For the EC2 instance, I used a persistent spot instance to reduce costs. If the instance is no longer needed, you can cancel the spot request to terminate it. Be careful, as deleting the instance without canceling the spot request will create a new instance.

I chose Ubuntu as the OS for EC2, thinking about the possibility of moving to other cloud services, VPS, or my own PC.

Once the instance is running, connect via SSH and update the packages.

$ sudo apt update
$ sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Set the local timezone. Since I live in Japan, I changed the timezone to Tokyo. I made sure to check, change, and re-check the timezone to ensure it was correct.

# check
$ timedatectl

# change
$ timedatectl list-timezones | grep Asia/Tokyo
$ sudo timedatectl set-timezone Asia/Tokyo

# re-check
$ timedatectl
Enter fullscreen mode Exit fullscreen mode

To change the SSH port number, I updated /etc/ssh/sshd_config and the security group settings.

$ hx /etc/ssh/sshd_config

#Port 22
↓
Port 2222
Enter fullscreen mode Exit fullscreen mode

With this, the setup of the development environment is complete.

Side Notes

Initially, I configured the SSD as the root disk and the HDD as the home directory. However, I was unhappy with the slow disk access speed, so I eventually switched to an SSD-only setup.

Currently, I am raising my children, so I can only work for 2–3 hours per day. To optimize costs, I stop the instance when it is not in use. After stopping the instance, I create an EBS snapshot and delete the volume to save more costs. The reason I am mindful of costs is that my allowance is small. As a result, I spend extra effort starting and stopping the instance to save money. And my remote dev environment does not have an Elastic IP, so I use the following alias to connect via SSH.

$ cat .bashrc
ssh-dev-ec2() {
  local user="ubuntu"
  local key="~/.ssh/de_kp.pem"
  local port=2222

  if [ -z "$1" ]; then
    echo "Usage: ssh-dev-ec2 <IP_ADDRESS>"
    return 1
  fi

  ssh -i "$key" "$user@$1" -p $port
}
Enter fullscreen mode Exit fullscreen mode

In the future, I want to use the AWS CLI to build a system that automates instance start and stop operations, and to connect a dev environment without specify IP address.

Top comments (0)