Skip to Content

Remote Developing with VsCode on AWS Cloud9 EC2 Instance

Posted on October 26, 2022 by

Categories: AWS

Tags:

Normally, I developed it on my local 13-inch Macbook using IntelliJ IDE. Still, as I started utilizing many docker container images, my little local hard drive rapidly became full, and my CPU struggled while working on many IDE projects at once.
My computer needs to be restarted frequently during the week, which takes a lot of time. As my laptop’s capabilities were limited, I decided to explore how I might use cloud resources while still having minimal influence on my commute to work.

I recently completed a project utilizing Infrastructure as Code and the AWS Cloud Development Kit (CDK). AWS CloudFormation may be used to a provision cloud infrastructure using CDK, an open-source software development framework. It provides a high-level object-oriented abstraction that enables the imperative definition of AWS resources with the help of contemporary programming languages. Using the CDK’s library of infrastructure components, you can quickly include AWS best practices in your infrastructure definition and distribute it without worrying about boilerplate logic.

I was trying to develop a way to continue using my local laptop as a developer while working on a remote cloud instance.

Benefits

  • drastically cut down on the amount of electricity my local laptop uses when working on projects
  • Enhance development efficiency by doing away with the requirement to sync local code with cloud instances.
  • There is no requirement to maintain two code versions, one on a local disc and the other in the cloud.
  • There are tasks that a laptop cannot perform, and a cloud instance offers more computational capacity.
  • You won’t be charged for the cloud instance if it is not activated when you need it.

Cloud9

An integrated development environment (IDE) for the cloud called AWS Cloud9 enables you to write, run, and debug code using just a web browser. It has a terminal, debugger, and code editor. You don’t need to install files or set up your development workstation to start new projects because Cloud9 is preconfigured with tools for major programming languages like Javascript, Python, PHP, and more.

Since the Cloud9 IDE is cloud-based, you may use any computer with an internet connection to work on your projects from anywhere. To pair programs and keep track of each other’s inputs in real-time, you may also rapidly share your working environment with your colleagues using Cloud9.

With the editor from my CDK project and a terminal with access to my AWS environment, we can see what Cloud9 looks like.

AWS Cloud9 contains a terminal with pre-authenticated AWS Command Line Interface access and sudo rights to the managed Amazon EC2 instance hosting your development environment. Thanks to this, you may swiftly execute commands and have direct access to AWS services.

Your Amazon EC2 instances created with AWS Cloud9 come with a default auto-hibernation setting of 30 minutes. With this configuration, your EC2 instances will shut down after 30 minutes of inactivity and only resume when you open the IDE again.

Because of this, you usually only pay for EC2 instances when you are actively working. While your instance has to restart, you may have some delay time when launching your IDE and lose any current terminal sessions (though you may use tools like tmux to store them). Depending on your use case, you may choose the auto-hibernation option and even choose “always on” to keep an EC2 instance running.

Although Cloud9 has made significant development, there are instances when you need a more powerful IDE. One such IDE is Visual Studio Code.

Yet, hey! What if you could run your Visual Studio Code IDE using the advantages of your Cloud9 environment?

Visual Studio Code remotely.

Visual Studio Code is a compact yet capable source code editor on your desktop. It contains extensions for many languages and runtimes and built-in support for JavaScript, Typescript, and Node.js.

However, VsCode is intriguing to us since it offers a remote development mode that enables us to use a distant computer as a fully functional development environment: You don’t need to store any source code locally. Each addition in the Distant Development extension pack from the marketplace can directly execute commands and other extensions within a remote system, giving the impression that everything is running locally.

The problem is that we could just reuse the managed EC2 instance that was launched with our Cloud9 IDE, giving us the option to manage the same source code using either Cloud9 or VsCode or both. We will also benefit from Cloud9’s auto-hibernation functionality, which will enable us to save money.