– AWS CLI
– an existing EC2 instance with an account private key on your local file system.
[Optional] If you use PuTTy ssh client, you may want to install and configure the Vagrant PuTTY plugin, by following instructions here: https://github.com/nickryand/vagrant-multi-putty. You will also need to make a symbolic link to the executable, using the following command.
> mklink D:\Vagrant\embedded\bin\putty.exe "C:\Program Files (x86)\PuTTY\putty.exe"
(1) Use the AWS CLI/Security Token Service to generate temporary credentials for AWS
> aws sts get-session-token
The credentials returned by this command will be valid for 1 hour.
(2) Install the Vagrant AWS plugin.
> vagrant plugin install vagrant-aws
(3) Add the “dummy” Box provided by the vagrant-aws project. This is a barebones Box compatible with AWS. We will flesh this out in the Vagrantfile to be created in the next step.
> vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
(4) Create a new directory to hold files for this Vagrant instance. I’m calling this vagrant-aws.
> mkdir vagrant-aws
(5) With your favorite text editor create a file called
Vagrantfile inside this new directory. Edit this file
vagrant-aws\Vagrantfile copying and pasting the following to the file (source).
Vagrant.configure("2") do |config| config.vm.box = "dummy" config.vm.provider :aws do |aws, override| aws.access_key_id = "YOUR KEY" aws.secret_access_key = "YOUR SECRET KEY" aws.session_token = "SESSION TOKEN" aws.keypair_name = "KEYPAIR NAME" aws.ami = "ami-7747d01e" override.ssh.username = "ubuntu" override.ssh.private_key_path = "PATH TO YOUR PRIVATE KEY" end end
(6) Now edit this text with the credentials returned by AWS STS (from above). You can use a different AMI (the current one given is for Ubuntu 12.04 x64) or change many other options, as described in the Vagrant AWS plugin documentation.
(7) Now you can bring the instance up with Vagrant, first making sure you are in the directory where you had created the Vagrantfile.
> cd vagrant-aws > vagrant up
To work on your new Vagrant VM, use
vagrant ssh or
vagrant putty if you set up Putty using the plugin mentioned below. Once you’re finished, you can use
vagrant destroy to completely blow away this instance, or some other vagrant command if you need to come back to the instance.