Why use Vagrant to launch EC2 instance?
EC2 instances can be deployed seamlessly using Vagrant. Once you setup Vagrant and configure it, launching an EC2 instance becomes as easy as running the command vagrant up. Such automation is especially useful when you have to launch a large fleet of EC2 instances quickly.
Setting up Vagrant on your machine
- Install vagrant:
`sudo apt-get install vagrant` 2. Initialize vagrant:
`vagrant init hashicorp/precise32`
`vagrant up`
(This will download the example virtualbox image from vagrant servers. It might take a few minutes) 3. Install vagrant aws plugin:
`sudo vagrant plugin install vagrant-aws` 4. Get the AWS Box image:
`vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box`
Launching the instance
- Create a directory in your home folder and from inside the directory, run
`vagrant init hashicorp/precise32`
(This will create a “Vagrantfile” in your directory) 2. Open your Vagrantfile, clear all contents and add the following. Please modify the values wherever necessary.
-
Save the file and run:
vagrant up --provider=aws
-
Your instance should be up and running in a few minutes.
The above configuration only contains the bare essential configurations. Here are some more configuration parameters.
availability_zone | Specify the desired availability zone. (ap-southeast-1a) |
instance_type | The default value of this if not specified is “m3.medium” |
private_ip_address | The private IP address to assign to an instance within a VPC |
instance_ready_timeout | The number of seconds to wait for the instance to become “ready” in AWS. Defaults to 120 seconds |
instance_package_timeout | The number of seconds to wait for the instance to be burnt into an AMI during packaging. Defaults to 600 seconds |
elastic_ip | Can be set to ‘true’, or to an existing Elastic IP address |
security_groups | An array of security groups for the instance. If this instance will be launched in VPC, this must be a list of security group Name. For a non-default VPC, you must use security group IDs instead |
subnet_id | The subnet to launch the instance inside |
associate_public_ip | true/false. If true, will associate a public IP address to an instance in a VPC |
The full list of options can be found here: https://github.com/mitchellh/vagrant-aws#configuration
Note: This guide is written for a *nix environment. The steps are similar for Windows based environments.
Comments