#121 AWS: Vagrant and AWS

In this short post I’ll describe how to use Vagrant and AWS instead of VirtualBox.
First, install Vagrant as described here. Once installed, install the AWS plug-in.

vagrant plugin install vagrant-aws

Next, we’ll power up an Amazon AWS Linux instance. Create a Vagrantfile with the following content.

# Require the AWS provider plugin
require 'vagrant-aws'
# Create and configure the AWS instance(s)
Vagrant.configure('2') do |config|

  # Use dummy AWS box = 'aws-centos'
  # Specify AWS provider configuration
  config.vm.provider 'aws' do |aws, override|
  # Read AWS authentication information from environment variables
  aws.access_key_id = "XKWY7YEW1X2YMLY3EYVX"
  aws.secret_access_key = "YTe+BMZZ5tr3OZn85gBhTTLzRugf3765Kw31-sHx"
  # Specify SSH keypair to use
  aws.keypair_name = "MyKeyPair"
  # Specify region, AMI ID, and security group(s)
  aws.region = "us-east-1"
  aws.ami = "ami-97785bed"
  aws.security_groups = ["sg22-EVERYWHERE"]
  aws.instance_type = "t2.micro"
  aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1', 'Ebs.VolumeSize' => 10 }]
  aws.tags = {
              'Name' => 'AWS Linux - Vagrant',
              'Environment' => 'Development'
  # Specify username and private key path
  override.ssh.username = "ec2-user"
  override.ssh.private_key_path = "/home/klimenta/.ssh/keypair.pem"

This is what these lines mean.
In lines 11 and 12, enter your AWS credentials for programmatic access. Line 14 tells which key pair to use.

Line 17 tells what AMI ID to use. You can use your own AMIs or AMIs from the marketplace. In my case I am using AWS Linux.

In line 18, specify the security groups that will be assigned to the instance. Use comma (,) to assign multiple groups. The name of the group that you have to specify can be found under Group Name, not Name.

Line 19 specifies the instance type. Make sure that the AMI supports that instance type, otherwise the build will fail. Line 20 specifies extra drive if needed with a size of 10GB. Lines 21-24 specify the tags. Line 26 tells Vagrant what username to use. In AWS Linux, the default is ec2-user. For some other AMIs, the default username might be centos, ubuntu. Check the AMI description for this. Finally, line 27 specifies the MyKeyPair from line 14 in PEM format. You have to save the certificate somewhere locally in order to SSH.
Now, you can power up the instance with:

vagrant up --provider=aws

And then you can log in with:

vagrant ssh

Or, when you are done, you can terminate the instance.

vagrant destroy
#122 AWS, pfsense: Site-to-site VPN using static routes
#112 AWS: IAM policy for Glacier
#129 vCenter, AWS: Backup VMs in vCenter to AWS S3
There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.