Skip to content

Instantly share code, notes, and snippets.

@tlockney
Last active Aug 29, 2015
Embed
What would you like to do?
This setup allows for quick hacking with an sbt console on an EC2 instance -- very useful for trying out the AWS APIs when you need to try things out. As an example, I wanted to make sure I understood how to get the various bits of meta-data that are visible only on EC2. Create the following files and run setup.sh to run everything.
---
- hosts: all
vars:
tasks:
- name: Install essential base packages
apt: pkg={{ item }} update_cache=yes
sudo: yes
with_items:
- openjdk-7-jdk
- curl
- tmux
- name: Retrieve sbt package
command: curl -O http://repo.scala-sbt.org/scalasbt/sbt-native-packages/org/scala-sbt/sbt/0.13.1/sbt.deb
- name: Install sbt package
command: dpkg -i sbt.deb
sudo: yes
- name: Initialize sbt
command: sbt exit
# you'll first want to create a keypair for EC2 -- I called mine 'vagrant' and downloaded
# the vagrant.pem to the directory where I was running all this (see below)
# also, I assume you already have vagrant and ansible installed
vagrant plugin install vagrant-aws
mkdir ec2-experiments
cd ec2-experiments
# This dummy box is used to bootstrap Vagrant on EC2
vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
vagrant up --provider=aws
Vagrant.configure("2") do |config|
config.vm.box = "dummy"
config.vm.provider :aws do |aws, override|
aws.access_key_id = "..."
aws.secret_access_key = "..."
# you'll need to create the EC2 keypair used here -- I called it vagrant for easy tracking
aws.keypair_name = "vagrant"
# you'll want to use a group that has at least SSH open
aws.security_groups = ["default"]
# you'll need to find an AMI that's appropriate for the region you're using
# use this tool to do that: https://cloud-images.ubuntu.com/locator/ec2/
aws.ami = "ami-c6402cf6"
# I wanted an instance with at least a few cores for faster compilation
aws.instance_type = "m1.xlarge"
aws.region = "us-west-2"
# You might not really need this, but I was trying to test how user-data showed up through
# The AWS java api
aws.user_data = "..."
# Set this to something identifiable so you can easily find your instance if you have more than a few
aws.tags = {
"Name" => "aws-experiments"
}
override.ssh.username = "ubuntu"
override.ssh.private_key_path = "vagrant.pem"
end
config.vm.provision "ansible" do |ansible|
# This isn't necessary, but can be useful if you run into trouble
ansible.verbose = 'vv'
ansible.playbook = "playbook.yml"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment