{"componentChunkName":"component---src-templates-blog-post-tsx","path":"/aws-cloud9-vs-code-remote/","result":{"data":{"site":{"siteMetadata":{"title":"inssein"}},"markdownRemark":{"id":"108ad5e9-c28a-5e3b-97e0-bcbcbe1c0673","excerpt":"If you followed my blog post, you now have a fully functioning cloud based integrated development environment. This is good enough to start out with, but lets…","html":"<p>If you followed my <a href=\"https://inssein.com/cloud-based-ide/\">blog post</a>, you now have a fully functioning cloud based integrated development environment. This is good enough to start out with, but lets take it to the next level.</p>\n<p>In this blog post, I will show you how you can use <a href=\"https://code.visualstudio.com/\">Visual Studio Code</a> and connect it to your AWS Cloud 9 development environment. This allows you to not have to setup anything on your local machine, except for having to install Visual Studio Code.</p>\n<p>Visual Studio Code is also the suggested IDE if you are following The Odin Project:</p>\n<blockquote>\n<p>VSCode is an excellent free code editor. It has outstanding add-on support and great Git integration. VSCode is the most popular code editor among Odin’s students and moderators, so support is easy to find in the community.</p>\n</blockquote>\n<h2>Pre-requisites</h2>\n<ol>\n<li>Download and install <a href=\"https://code.visualstudio.com/\">Visual Studio Code</a>.</li>\n<li>Add <a href=\"https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack\">Remote Development Extension Pack</a> to Visual Studio Code.</li>\n</ol>\n<h2>Connect to SSH</h2>\n<p>Since your AWS Cloud 9 instance is just a regular AWS EC2 instance, we can customize it so that we can connect to it from anywhere in the world.</p>\n<p>First step is that we have to allow SSH connections from the outside. To do this:</p>\n<ol>\n<li>Go to the <a href=\"https://us-west-2.console.aws.amazon.com/ec2/v2/home?region=us-west-2#Instances:sort=instanceId\">Amazon EC2 Console</a>.</li>\n<li>You should only have one instance if you just created this account, and it should be auto selected. Otherwise, click on the Cloud 9 instance.</li>\n<li>In the description tab at the bottom, there should be a row for “Security groups”, with one security group in that row. Click on the name of the security group.</li>\n<li>Click in the “Inbound” tab at the bottom.</li>\n<li>By default, I had two rows already allowing SSH connections to what looks like an internal Amazon IP range so that Cloud 9 can connect to this machine via SSH. Since we want to be able to connect from anywhere, click on “Edit”.</li>\n<li>I delete my second row, and in my first row, I have set the source to “Anywhere”. It should look like this:\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto;  max-width: 590px;\"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/1bb079e87dbdcf81016300f1a7255b1c/ad1ae/inbound-rules.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 28.72246696035242%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAABYlAAAWJQFJUiTwAAAA8klEQVQY012OC26DMBBEuf9BcpIeAVQqQikJHxuQgz/YgKgmXkcBWqSnnWV2Zx3FcYI4SZCmX2hahpZxMN6h9ZpxHiBNNCdeXnfyWnz6jKgoCtR1jSzLUFcVmqZBfr2CMYayvAW4Xya6rtuhvR8P93PkDX3vdzgiMq210Fpjnmc452CMwbquqPiIrBwwCAmlJJZl2RnHEUKIULWfD/1jRJTneTAoUCkVeGspFR5+iPppmsKhd6VHHP8M6JNSInLO7kHG6D3wQIWlbdv+8HvSk1txEwt6EQJnTP6atS5cfVX3r7cw9Joz5tAll7h83JF+13gCBxTGgEhKsfYAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Inbound Rules\"\n        title=\"Inbound Rules\"\n        src=\"/static/1bb079e87dbdcf81016300f1a7255b1c/fcda8/inbound-rules.png\"\n        srcset=\"/static/1bb079e87dbdcf81016300f1a7255b1c/12f09/inbound-rules.png 148w,\n/static/1bb079e87dbdcf81016300f1a7255b1c/e4a3f/inbound-rules.png 295w,\n/static/1bb079e87dbdcf81016300f1a7255b1c/fcda8/inbound-rules.png 590w,\n/static/1bb079e87dbdcf81016300f1a7255b1c/efc66/inbound-rules.png 885w,\n/static/1bb079e87dbdcf81016300f1a7255b1c/c83ae/inbound-rules.png 1180w,\n/static/1bb079e87dbdcf81016300f1a7255b1c/ad1ae/inbound-rules.png 2270w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></li>\n</ol>\n<h2>Allow Password Based Authentication</h2>\n<p>We are going to setup simple password based authentication so we can connect to the EC2 instance. This is <em>not</em> the way I’d recommend to access production based machines, as you should really be setting up access via <a href=\"https://en.wikipedia.org/wiki/Public-key_cryptography\">Public key authentication</a>. However, I want to keep this as simple as possible.</p>\n<ol>\n<li>We need to setup a password for our account. In the terminal in Cloud 9, type <code class=\"language-text\">sudo passwd ubuntu</code>, and then type in a password of choice.</li>\n<li>\n<p>We need to now enable password based authentication. If you already know how to use a terminal, edit <code class=\"language-text\">/etc/ssh/sshd_config</code> and set <code class=\"language-text\">PasswordAuthentication</code> to <code class=\"language-text\">yes</code>. If you are not familiar, follow these steps:</p>\n<ul>\n<li>Type in <code class=\"language-text\">sudo vim /etc/ssh/sshd_config</code> in the terminal.</li>\n<li>Type in <code class=\"language-text\">/PasswordAuth</code> to find the text, and then hit enter.</li>\n<li>You are now on the line that needs to be changed. Press <code class=\"language-text\">i</code> to get into insert mode.</li>\n<li>Go to the end of the line, replace <code class=\"language-text\">no</code> with <code class=\"language-text\">yes</code>.</li>\n<li>To exit insert mode, press escape.</li>\n<li>Type <code class=\"language-text\">:wq</code> into the console and press enter (this writes the file, and exits).</li>\n<li>I’ve hopefully given you your first taste of <code class=\"language-text\">vim</code>. To learn more, check out <a href=\"https://www.openvim.com/\">OpenVim</a>.</li>\n</ul>\n</li>\n<li>Type <code class=\"language-text\">sudo service ssh restart</code> to restart the SSH service.</li>\n</ol>\n<h2>Connect to Your Cloud 9 Instance</h2>\n<p>Now the EC2 instance is ready to be connected to via Visual Studio Code.</p>\n<ol>\n<li>We need to get the public hostname for our EC2 instance. To do this, lets go back to <a href=\"https://us-west-2.console.aws.amazon.com/ec2/v2/home?region=us-west-2#Instances:sort=instanceId\">EC2 AWS Console</a>, and select our Cloud 9 instance. In the description tab, there will be a Public DNS row. Let’s copy this address.</li>\n<li>Open visual studio code.</li>\n<li>On the bottom left, there is a green button that shows up once you have installed the Remote Development Extension Pack. Let’s click on this.</li>\n<li>Use the arrows keys to select “Remote-SSH: Connect to Host…“.</li>\n<li>In the next prompt, select “Add New SSH Hosts…“.</li>\n<li>In the next dialog box, enter <code class=\"language-text\">ssh ubuntu@</code> and then paste what we copied in step 1.</li>\n<li>In the next dialog box, pick a file to save your SSH config. I am on a Mac, so I selected my local ssh config which is <code class=\"language-text\">/Users/inssein/.ssh/config</code>.</li>\n<li>A prompt will show on the bottom right saying that the host has been added. In this prompt, click on the “Connect” button.</li>\n<li>A new Visual Studio Code window will open, and it will connect you to the EC2 instance. Since we are using password based auth, it will ask you for the password every time.</li>\n</ol>\n<h2>Hello World</h2>\n<p>Now that you are connected to the Cloud 9 environment via Visual Studio Code, I am going to show you two small examples.</p>\n<p>First, let’s edit the <code class=\"language-text\">index.html</code> file we created in the first blog post.</p>\n<ol>\n<li>Click on the “Explorer” icon, which on the top left.</li>\n<li>Click on the “Open Folder” button.</li>\n<li>In the next dialog box, type in <code class=\"language-text\">environment</code>, so that it reads <code class=\"language-text\">/home/ubuntu/environment</code> (environment is the folder Cloud 9 uses).</li>\n<li>Hit enter and Visual Studio Code should reload with the environment folder open.</li>\n<li>In the explorer, the <code class=\"language-text\">environment</code> folder should be open. Lets select the <code class=\"language-text\">index.html</code> file, and change <code class=\"language-text\">&lt;h1&gt;Hello World&lt;/h1&gt;</code> to <code class=\"language-text\">&lt;h1&gt;Hello Visual Studio Code&lt;/h1&gt;</code>, and then save the file.</li>\n<li>If you still have the separate browser window open from the previous blog post, reload it, otherwise, if you go back into Cloud 9 and preview the file, you should see your new changes in the browser.</li>\n</ol>\n<p>The second quick example is to show you that you can use the terminal inside Visual Studio Code just like you could with AWS Cloud 9. To try this, select <code class=\"language-text\">Terminal</code> in the top file menu, and then select <code class=\"language-text\">New Terminal</code>.</p>\n<h2>What’s Next</h2>\n<p>You now have a local IDE hooked up to a remote development environment, without installing anything on your local machine.</p>\n<p>The one annoying thing with this setup is that every time you start it, it will ask you for your password. As I mentioned before, my goal was to get your playing around with a terminal and the IDE first, and then if you are still enjoying it, I recommend you setup key based authentication. Maybe this will be my next blog post.</p>","timeToRead":5,"frontmatter":{"title":"Cloud 9 + Visual Studio Code Remote","date":"January 26, 2020","description":"A guide on how to connect Visual Studio Code to your AWS Cloud 9 Environment"}}},"pageContext":{"slug":"/aws-cloud9-vs-code-remote/","previous":{"fields":{"slug":"/cloud-based-ide/"},"frontmatter":{"title":"Free cloud based integrated development environment"}},"next":null}}}