/aws-wrapper

Scripts for our most common interactions with AWS

Primary LanguageRubyApache License 2.0Apache-2.0

aws-wrapper

Build Status

Scripts for our most common interactions with AWS. For documentation on a particular script, run it without arguments.

Before running any of the examples, you will need to have an AWS IAM user, with your API credentials in the conventional location: ~/.aws/credentials.

Being a sudo-enabled user is highly recommended - even if using homebrew. You also need to have python pip and install the aws command line interface (AWS CLI), plus ruby management stuff like Ruby Version Manager (rvm) and Gem (gem) to install the required version of ruby and to gem install bundler. Power tip: bundle install in the project directory does a lot of heavy lifting to enable things.

Typically, bare servers can be set up:

bundle exec scripts/build.rb --name abc.wgbh-mla-test.org

And then set up the load balancers:

bundle exec scripts/build.rb --name abc.wgbh-mla-test.org --setup_load_balancer

The current user is added to the priv group by default, but another user can be added to the group:

bundle exec scripts/group_add.rb --user someone_else --group abc.wgbh-mla-test.org

and then that user can swap them:

bundle exec scripts/swap.rb --name abc.wgbh-mla-test.org

and then stop the demo instance to save money, and restart before the next swap:

bundle exec scripts/stop.rb --name demo.abc.wgbh-mla-test.org
bundle exec scripts/start.rb --name demo.abc.wgbh-mla-test.org

and rsync a given directory from live to demo:

bundle exec scripts/rsync.rb --name abc.wgbh-mla-test.org --path /var/www/abc/something

log in to the demo machine:

ssh `bundle exec scripts/ssh_opt.rb --name demo.abc.wgbh-mla-test.org`

or just get the IPs:

bundle exec scripts/ssh_opt.rb --name demo.abc.wgbh-mla-test.org --ips_by_dns
bundle exec scripts/ssh_opt.rb --name abc.wgbh-mla-test.org --ips_by_dns
bundle exec scripts/ssh_opt.rb --name abc.wgbh-mla-test.org --ips_by_tag

or for a one-liner:

bundle exec scripts/sudo.rb --name abc.wgbh-mla-test.org --command 'echo "I am sudo"'

to get a handle on all the dependent resources:

bundle exec scripts/list.rb --name abc.wgbh-mla-test.org

and if this is development and we want to clear the slate:

bundle exec scripts/destroy.rb --name abc.wgbh-mla-test.org

Organization

Scripts Utility Classes AWS Wrapper Client Wrappers Base Wrapper
scripts/build.rb lib/util/builder.rb lib/util/aws_wrapper.rb lib/core/elb_wrapper.rb lib/core/base_wrapper.rb
scripts/.........rb lib/util/.........er.rb lib/core/..._wrapper.rb

Each layer should require only from the layer immediately below.

  • Scripts are for use by the end user. Each should be self-documenting if run without other arguments. Scripts are thin wrappers for ...
  • Utility Classes, each of which defines one interaction with AWS. These classes are the targets of the tests.
  • AWS Wrapper simply requires all of the Client Wrappers in one place.
  • Client Wrappers each define the interactions we need for a particular AWS service.
  • Base Wrapper provides logging and the like.

Reference

The scripts create all kinds of interrelated AWS resources. If you want to keep an eye on them (may need to change region to match yours):