Vagrant with AWS and PyCharm / Visual Studio Code

Vagrant is awesome tool for creating and sharing environments running in VirtualBox, Vmware, Hyper-V, etc.
But nowadays we may need to run AWS Linux as well as CentOS, Ubuntu and Windows.

Powerful IDEs such as PyCharm can wok with Vagrant machines, which is really useful, e.g. while debugging scripts.

So in this post I’ll show you how to do it.

1. Install aws plugin:

2. Clone Vagrant box (it contains only metadata.json with aws provider):

3. Check available options: https://github.com/mitchellh/vagrant-aws
4. Create Vagrantfile, see my example:

Vagrant.configure("2") do |config|
  config.vm.box = "aws"

  config.vm.provider :aws do |aws, override|
    aws.access_key_id = "YOUR_KEY"
    aws.secret_access_key = "YOUR_SECRET_KEY"
    aws.keypair_name = "YOUR_KEYPAIR_NAME"
    aws.instance_type = "t2.micro"
    aws.region = "us-west-2"
    aws.ami = "ami-f303fb93"
    aws.security_groups = "YOUR_SECURITY_GROUP_NAME"
    aws.elb = "YOUR_ELB_NAME"

    override.ssh.username = "ec2-user"
    override.ssh.private_key_path = "/Users/kagarlickijd/Google\ Drive/SSH/key-oregon.pem"
  end
end

 

5. Open PyCharm, install Vagrant plugin and set Vagrant executable which is in the /opt/vagrant/bin/vagrant by default;
6. Now you are able to use Vagrant from PyCharm:

Screen Shot 2016-06-14 at 20.38.11

7. But there’re some limitations: rsynс is used for vagrant folder sync, so you need to run vagrant reload to see a new content.
However you can use git, S3 or FTP to sync content.

Visual Studio Code is another nice IDE, it’s light and free, but not so comfortable as PyCharm.
To use Visual Studio Code with Vagrant install vscode-vagrant plugin and check available options:

Screen Shot 2016-06-14 at 21.55.20

As you can see, from Visual Studio Code you can also run ssh.
You can install Vagrantfile Support plugin in Visual Studio Code to highlight Vagrantfile syntax:

Screen Shot 2016-06-14 at 22.01.37

There’s no native plugin to support Vagrantfile in PyCharm, but you can associate Vagrantfile with bash plugin syntax highlight:

Screen Shot 2016-06-14 at 22.52.17

But it’s not a very good idea, because Vagrantfile is simple and you probably won’t need even syntax highlight.

Vagrant for DevOps table of contents