Skip to content

Latest commit

 

History

History
119 lines (84 loc) · 5.91 KB

README.md

File metadata and controls

119 lines (84 loc) · 5.91 KB

AWS Dev Instance for VScode

Overview

Are you fed up with trying to awkwardly develop on a windows machine, tried WSL2 and woke up one day to it being totally bawked by Windows 11? Fear not - Your free-tier AWS dev environment is here! This is a slight extension of Derek Morgan's course that teaches you how to build a dev instance in AWS using terraform.

⚠️ Advice!! Take Derek's course before proceeding ⚠️

This repo is based on infrastructure deployed in Derek Morgan's course "Build a Dev Environment with AWS and Terraform". If you want to understand the underlying terraform code and what it's doing I really recommend taking the time to go through Derek's awesome content.


What you'll get..

After running through this readme you will have a way to spin up a development instance in AWS at will. It will be accessible from your local machine over SSH using the native plugin for VScode. Your Dev instance will:

  • Be running Ubuntu
  • Have python3 installled
  • Have Docker installed
  • Have Terraform installed
  • Have an IAM role attached with Admin access to your AWS account

So, what are you waiting for!? Clone this repo and let's do it.

Prerequisites

  • A Windows machine
  • A working installation of vscode
  • Chocolatey package manager for Windows - Not essential but helps!

Contents

  1. Creating an AWS account
  2. Creating Terraform credentials in AWS
  3. Creating an SSH key
  4. Installing terraform
  5. Deploying your dev instance
  6. Connect to your instance

Creating an AWS account

Follow this guide to create and secure a new AWS account.

Creating terraform credentials in AWS

IAM Console

  • Create a new user with programatic access only and save the Access and Secret keys somewhere safe!

Create User

  • Run .\scripts\aws_setup.ps1 to generate an AWS credentials file (assuming you don't have one already). This will give Terraform what it needs to create resources in your account.

AWS Credentials File

Creating an SSH key

  • In a PowerShell window enter the command ssh-keygen -t ed25519 to create your keypair. Generate SSH Key
  • Copy your public key to the root directory of this repo. cp ~/.ssh/awsDevInstanceKey.pub . you'll need it later!

Installing Terraform

  • If you already have Chocolatey installed then simply run choco install terraform
  • If you're unable to install chocolatey then follow these steps to get terraform installed.

Deploying your Dev instance

  • Firstly generate your tfvars file by running .\scripts\generate_tfvars.ps1
    • This script will pull your public IP from whatsmyip.com and also set the local_development variable to true
  • Run terraform init to initialise the directory
  • Run terraform apply. Terraform will output a list of things that will happen, i.e stuff that will be created in your AWS account. Like this:

Teraform Apply

  • Type yes and hit enter.
  • Terraform will now go off and create the below infra in your account

Architecture Diagram

Github access

Remember in an earlier section when I said to copy your public key as you'll need it later? This is that time!

Firstly we need to add that SSH key to Github, so copy the contents of your public key to your clipboard and follow the guide here

Adding SSH Key to Github

  • Copy the name of your SSH key to your clipboard awsDevInstanceKey if you followed these instructions exactly.
  • Run ./scripts/github_setup.ps1 and paste your keyname in.

Copying SSH to remote host

  • The script will grab the SSH key you've specified and copy it to the remote host. It will also copy an SSH config file telling the remote host to use that key for github access.

  • If you didn't follow exactly, or would like to use a different SSH key for github access. Then all you need to do is edit the below line in ./scripts/config to reflect the correct key name.

Host github.com
  HostName github.com
  IdentityFile ~/.ssh/awsDevInstanceKey <-- THIS ONE!!

Connecting to your instance

  • Once your terraform completes, you will see an output that looks like this:
ssh_config_info = <<EOT
Host 3.8.2.100
  HostName 3.8.2.100
  User ubuntu
  IdentityFile ~/.ssh/devInstanceKey

EOT
  • This is the SSH information for your brand new EC2 dev instance
  • Run .\scripts\add_to_ssh_config.ps1 to add the SSH information to your config file and allow you to connect.
  • Install the SSH extension to vscode
    • Click on Extensions (ctrl+shift+x) type ssh into the search box and install Remote - SSH by Microsoft.
  • Press ctrl+shift+p to open the command pallet and type ssh click Remote-SSH: Connect to host...
  • The FIRST IP address in the list will be your AWS instance, as the script will always place the latest IP address at the top of the config file. Click on it!
  • Click on Linux
  • Click on continue
  • press ctrl + ' to open a terminal window and run chmod 600 ~/.ssh/awsDevInstanceKey (or your custom key name)
  • Your instance is now ready to use and has permissions to your AWS account via an instance role as well as github access.