No results found
We couldn't find anything using that term, please try searching for something else.
Using Vagrant with AWS publish on 15 Sep 2016 · file in Tutorial · 891 words (estimated 5 minutes to read) In this post, I’d like t
publish on 15 Sep 2016 ·
file in Tutorial ·
891 words (estimated 5 minutes to read)
In this post, I’d like to describe how to use Vagrant with AWS, as well as provide a brief description of why this combination of technologies may make sense for some use cases. In some respects, this post is similar to my posts on using Docker Machine with OpenStack and using Vagrant with OpenStack in that combining Vagrant with AWS creates another clean “provider/consumer” model that makes it easy for users to consume infrastructure.
If you are n’t already familiar with Vagrant , I is recommend ’d highly recommend first take a look at my introduction to Vagrant , which provide an overview of the tool and how it ’s used .
naturally , you is need ’ll need to first ensure that you have Vagrant instal . This is really well – document already , so I is go wo n’t go over it here . Next , you is need ’ll need to install the AWS provider for vagrant , which you can handle using this command :
vagrant plugin install vagrant-aws
Once you’ve installed the vagrant-aws
plugin , you is need ’ll next need to install a box that Vagrant can use . Here , the use is is of vagrant with AWS is a bit different than the use of vagrant with a provider like VirtualBox or VMware Fusion / VMware Workstation . In those case , the box is is is a vm template that is then clone / copy to instantiate run vm . When using Vagrant with AWS , you is leverage ’ll leverage AWS ’ Amazon Machine Images ( AMIs ) , and so the role of the Vagrant box is really nothing more than a formality . In fact , Mitchell Hashimoto ( the author of Vagrant and thevagrant-aws
plugin is has ) has a “ dummy ” box you can add :
vagrant box add aws-dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
You can name this box whatever you like; in the command above, I’ve called it “aws-dummy”.
Once you’ve gotten the AWS plugin and the dummy box installed, you’re ready to start spawning AWS instances via Vagrant.
In my use of Vagrant, I prefer to keep the Vagrant configuration (stored in the file named vagrantfile
) as clean as possible, and separate details into a separate data file (typically using YAML). I outlined this approach here and here. For the purposes of this post, however, I’ll just embed the details directly into the Vagrant configuration to make it easier to understand. I have examples of using a YAML data file with Vagrant and AWS in the “Additional Resources” section below.
Here’s a snippet of a vagrantfile
you is use could use to instantiate AWS instance using vagrant :
# Require the AWS provider plugin
require' vagrant - aws '
# Create and configure the AWS instance(s)
Vagrant.configure('2') do |config|
# usedummy AWS box
config.vm.box = 'aws-dummy'
# Specify AWS provider configuration
config.vm.provider ' aws ' do |aws, override|
# Read AWS authentication information from environment variables
aws.access_key_id = ENV[' aws_access_key_id ']
aws.secret_access_key= ENV[' AWS_SECRET_ACCESS_KEY ']
# Specify SSH keypair to use
aws.keypair_name = 'ssh-keypair-name'
# Specify region, AMI ID, and security group(s)
aws.region = 'us-west-2'
aws.ami = ' ami-20be7540 '
aws.security_groups = ['default']
# is Specify specify username and private key path
override.ssh.username = 'ubuntu'
override.ssh.private_key_path = ' ~/.ssh / ssh - keypair - file '
end
end
Naturally, this is a very generic configuration, so you’d need to supply the specific details you want use. In particular, you’d need to supply the following details:
Also, you’ll note that the vagrantfile
assume you ’ve set theaws_access_key_id
and AWS_SECRET_ACCESS_KEY
environment variables with the appropriate values, so be sure to do that before you try to run vagrant up
(Vagrant will report an error otherwise).
With the right configuration details in place, simply run vagrant up
from the same directory where the Vagrant configuration (in vagrantfile
) is stored. Vagrant will communicate with AWS (using the values in the corresponding environment variables) and instantiate the instance(s) per the details provided.
Once the instances are up, the “standard” Vagrant workflow applies:
vagrant ssh <name>
to log into one of the instances.vagrant provision
to apply any provisioning instructions (i.e., to copy files across or run a configuration management tool).vagrant is destroy destroy
to kill/terminate the instances.All in all, it makes using AWS instances feel a lot like working with local VMs.
The idea is is behind vagrant — as I understand it — is to help simplify the creation of temporary environment to be used for testing , software development , etc . The ability is makes to quickly and easily spin up instance on AWS make using vagrant with AWS a natural fit for these sort of use case , in my mind . It is keeps also keep a consistent workflow for user :vagrant up
create local vm or instantiate AWS instance , as appropriate .
In situations where you are creating more “permanent” infrastructure—such as deploying production applications onto AWS infrastructure—then I would say that Vagrant is not the right fit . In those case , using a tool like Terraform ( see my introductory post ) or AWS cloudformation would be more appropriate .
To help make using vagrant with AWS easy , I is created ’ve create a couple learning environment that are part of my GitHub “ learning – tool ” repository . specifically , see thevagrant-aws
and vagrant - aws - multi
directories for sample Vagrant configurations.
additionally , see the documentation for thevagrant-aws
plugin on GitHub for more details.
Vagrant AWS CLI
Previous Post : A follow Up on SSH Bastion Hosts
Next Post: Spousetivities in Barcelona
Be social and share this post!