Skip to content

Instantly share code, notes, and snippets.

@ozzyjohnson
Last active June 19, 2018 15:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ozzyjohnson/d62b0c8183f0d4d7448e to your computer and use it in GitHub Desktop.
Save ozzyjohnson/d62b0c8183f0d4d7448e to your computer and use it in GitHub Desktop.
Use an EC2 spot instance with Vagrant

Setup:

git clone git@github.com:nabeken/vagrant-aws.git
cd vagrant-aws
git checkout spot-3
gem build vagrant-aws.gemspec
vagrant install plugin vagrant-aws-0.5.0.gem

Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "dummy"

  config.vm.provider :aws do |aws, override|
    aws.instance_type = "c4.large"
    aws.keypair_name = "keypair"
    aws.ami = "ami-9eaa1cf6"
    aws.region = "us-east-1"
    aws.subnet_id = "subnet-a1b2c3d4"
    aws.tags = {
      'Name' => 'name',
      'client' => 'client'
    }
    aws.security_groups = ['sg-a1b2c3d4']

    aws.region_config "us-east-1" do |region|
        region.spot_instance = true
        region.spot_max_price = "0.02"
    end

    override.ssh.username = "ubuntu"
    override.ssh.private_key_path = "keypair.pem"
  end
end

Run:

vagrant up --provider=aws
@octplane
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment