DevOps.com

Where the world meets DevOps

  • Latest
    • Articles
    • Features
    • Most Read
    • News
    • News Releases
  • Topics
    • AI
    • Continuous Delivery
    • Continuous Testing
    • Cloud
    • Culture
    • DevSecOps
    • Enterprise DevOps
    • Leadership Suite
    • DevOps Practice
    • ROELBOB
    • DevOps Toolbox
    • IT as Code
  • DevOps Chats
  • Webinars
    • Upcoming
    • On-Demand Webinars
  • Library
  • Events
    • Upcoming Events
    • On-Demand Events
  • Sponsored Communities
    • AWS Community Hub
    • CloudBees
    • IT as Code
    • Perforce DevSecOps
    • Rocket on DevOps.com
    • Traceable on DevOps.com
  • Related Sites
    • MediaOps
    • Container Journal
    • Security Boulevard
    • SweetCode.io
    • Digital Anarchist
    • DevOps TV on YouTube
    • DevOps Chat on SoundCloud
    • DevOps Connect
    • DevOps Dozen
  • Media Kit
  • Follow Us
    • Twitter
    • Google News
    • LinkedIn
    • Facebook
    • DevOps TV on YouTube
    • Email
  • AI
  • Cloud
  • Continuous Delivery
  • Continuous Testing
  • DevSecOps
  • Leadership Suite
  • Practices
  • ROELBOB
  • Low-Code/No-Code
  • IT as Code
  • More Topics
    • Application Performance Management/Monitoring
    • Culture
    • Enterprise DevOps

Home » Blogs » DevOps Practice » DevOps Primer: Using Vagrant with AWS

DevOps Primer Vagrant AWS

DevOps Primer: Using Vagrant with AWS

By: contributor on January 2, 2018 Leave a Comment

One of the most common problems in modern software development is the phrase, “It works on my machine,” when a particular piece of code runs on developer’s machine but produces error on other team member’s machine. Thankfully, now there is a plugin that can help determine why something works only in particular environments, turning the phrase into more an observation than an excuse.

Recent Posts By contributor
  • How to Ensure DevOps Success in a Distributed Network Environment
  • Dissecting the Role of QA Engineers and Developers in Functional Testing
  • All Day DevOps, Viewed from the Outside
More from contributor
Related Posts
    Related Categories
  • Blogs
  • DevOps Practice
    Related Topics
  • AWS
  • DevOps tool
  • vagrant
Show more
Show less

Vagrant to the Rescue

Vagrant is a tool for building and maintaining portable software development environments. It isolates your project’s dependencies and configuration from your projects without disturbing the tools your application is consuming. You could easily reproduce similar environments on other machines by using the same configuration as your machine.

Basic Concepts in Vagrant

Before going further, it is important to understand the following basic concepts that are essential to the working of Vagrant.

Provisioners

Provisioners provide automation for installing different software and configurations. It is useful in cases when you don’t want to install software manually to your machine.

Providers

Providers provide basic services that are required to run your machine. Although Vagrant provides support for VirtualBox, Hyper-V and Docker, other providers can also be used through appropriate plugin.

Boxes

Boxes are Vagrant environment packages that can be copied to any other machine to replicate a similar environment. Vagrant provides a repository of these boxes that can be downloaded, and you can contribute to the list by adding your own customized box.

Install the Plugin

The first step in the process is to make sure that you have Vagrant installed on your machine. As I mentioned earlier, you could use providers by installing the respective plugins. For the purpose of this tutorial, I will download the vagrant-aws plugin through the following command:

vagrant plugin install vagrant-aws

Next, verify the plugin installation through the command:

vagrant plugin list

The vagrant-aws plugin should be present in the plugins list

Set Up the Vagrant Box

After installing plugin, the next step is to install a Vagrant box. The problem is that there is no box for AWS provider. To make things work, I recommend you use the dummy box provided by Mitchell Hashimoto.

Run the following command to add the dummy box:

vagrant box add aws https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box

Although I have named the box aws, you can give it any name that works for you. Once the process finishes, I am ready to create AWS instances.

Create the Instance

Run the vagrant init command to create a vagrant file:

vagrant init

Next, edit the vagrant file as follows:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Require the AWS provider plugin
require ‘vagrant-aws’

# Creating and configuring the AWS instance
Vagrant.configure(‘2’) do |config|

# Use dummy AWS box
config.vm.box = ‘aws’

# Specify configuration of AWS provider
config.vm.provider ‘aws’ do |aws, override|
# Read AWS authentication information from environment variables
aws.access_key_id = ‘ABCR2NDJKZJIAJ5QVXGJK’
aws.secret_access_key = ‘WAuZE39lKHXAJnCfbZf2y6DzRfeCsPUU/yZMRDWo’

# Specify SSH keypair to use
aws.keypair_name = ‘vagrant’

# Specify region, AMI ID, Instance and security group
aws.region = ‘ap-southeast-2’
aws.ami = ‘ami-14b55f76’
aws.instance_type = ‘t2.micro’
aws.security_groups = [‘default’]

# Specify username and private key path
override.ssh.username = ‘ubuntu’
override.ssh.private_key_path = ‘~/vagrant/vagrant’
end
end

Vagrantfile Explained

The following list explains the important variables and aspects of the above file:

  • config.vm.box : Specify the box. Using dummy aws box for AWS deployment
  • aws.access_key_id : Access key ID of your Amazon account
  • aws.secret_access_key : The secret access key for your Amazon account
  • aws.keypair_name : Your SSH keypair in AWS
  • aws.region : The AWS region in which you want to create your instance
  • aws.ami : The AMI ID you want to use. AMI specifies the information needed to launch a virtual machine within EC2
  • aws.instance_type : The AWS instance you want to create
  • aws.security_groups : Specify the names of security groups that will be applied to your instance
  • override.ssh.username : The username that will be used to access the instance
  • override.ssh.private_key_path : The path of your SSH private key

Launch the Instance

After configuring the Vagrantfile, I will simply run the vagrant up command. Vagrant will launch an AWS instance through the AWS AMI provided in the configuration using the credentials provided in the Vagrantfile.


You can view the newly created instance in the AWS console panel.

You can now SSH into your AWS instance or perform other Vagrant operations.

Final Words

As you can see, using Vagrant to launch a AWS instance is simply a matter of installing the plugin and then launching the instances through easy steps. If you need help with the process, do leave a comment below.

About the Author / Ali Azmi

Ali Azmi is Associate DevOps Engineer at Cloudways – A Managed PHP Cloud Hosting Platform. He is skilled in developing PHP applications particularly in Laravel. He is passionate about contributing to open source projects.

Filed Under: Blogs, DevOps Practice Tagged With: AWS, DevOps tool, vagrant

Sponsored Content
Featured eBook
The State of Open Source Vulnerabilities 2020

The State of Open Source Vulnerabilities 2020

Open source components have become an integral part of today’s software applications — it’s impossible to keep up with the hectic pace of release cycles without them. As open source usage continues to grow, so does the number of eyes focused on open source security research, resulting in a record-breaking ... Read More
« AI Delivering on the Business Analytics Promise
A Happy New Year to All! »

TechStrong TV – Live

Watch latest episodes and shows

Get The Top Stories of the Week

  • View DevOps.com Privacy Policy

Upcoming Webinars

Realize the Promise of Value Stream Management With Plutora
Wednesday, June 23, 2021 - 11:00 am EDT
Herding Metrics in Cloud Native Environments
Wednesday, June 23, 2021 - 1:00 pm EDT
New Approach to Testing OTT Media & Entertainment in Telecom
Wednesday, June 23, 2021 - 3:00 pm EDT

Upcoming Webinars

Wed 23

Realize the Promise of Value Stream Management With Plutora

Wed, June 23, 11:00 am - 12:00 pm EDT
Wed 23

Herding Metrics in Cloud Native Environments

Wed, June 23, 1:00 pm - 2:00 pm EDT
Wed 23

New Approach to Testing OTT Media & Entertainment in Telecom

Wed, June 23, 3:00 pm - 4:00 pm EDT

More Webinars

Past Webinars

Latest from DevOps.com

Plutora Dives Deeper into Value Stream Analytics Data
June 22, 2021 | Mike Vizard
GitLab Updates Approach to Integrating DevOps Workflows
June 22, 2021 | Mike Vizard
How Containers Simplify DevOps Workflows and CI/CD Pipelines
June 22, 2021 | Kirby Wadsworth
Report: The State of Cloud-Native Application Security
June 22, 2021 | Bill Doerrfeld
Best Practices for Modern IT Incident Management
June 21, 2021 | Charlene O'Hanlon

Most Read on DevOps.com

Learning ‘The Third Way’ of DevOps – Conti...
June 17, 2021 | Marc Hornbeek
Using Chaos Engineering to Build Resilient Systems
June 18, 2021 | Ariel Assaraf
How Real-Time Debugging Improves Reliability
June 17, 2021 | Josh Hendrick
Grafana Labs Acquires k6 to Add Open Source Load Testing Too...
June 17, 2021 | Mike Vizard
PagerDuty Allies with JFrog to Modernize IT Incident Managem...
June 17, 2021 | Mike Vizard

On-Demand Webinars

DevOps.com Webinar ReplaysDevOps.com Webinar Replays

Download Free eBook

Hybrid Cloud Security 101
New call-to-action
  • Home
  • About DevOps.com
  • Meet our Authors
  • Write for DevOps.com
  • Media Kit
  • Sponsor Info
  • Copyright
  • TOS
  • Privacy Policy

© 2021 ·MediaOps Inc.All rights reserved.

Our website uses cookies. By continuing to browse the website you are agreeing to our use of cookies. For more information on how we use cookies and how you can disable them, please read our Privacy Policy.