Skip to content

Instantly share code, notes, and snippets.

@mdub
Last active December 23, 2018 14:12
Show Gist options
  • Select an option

  • Save mdub/5654700 to your computer and use it in GitHub Desktop.

Select an option

Save mdub/5654700 to your computer and use it in GitHub Desktop.
A simple Ruby-based AWS console
#! /usr/bin/env ruby
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
require 'aws-sdk'
access_key_id = ENV.fetch("AWS_ACCESS_KEY_ID")
secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY")
region = ENV.fetch("AWS_DEFAULT_REGION", "ap-southeast-2")
config = {
:access_key_id => access_key_id,
:secret_access_key => secret_access_key,
:cloud_formation_endpoint => "cloudformation.#{region}.amazonaws.com",
:ec2_endpoint => "ec2.#{region}.amazonaws.com",
:elastic_beanstalk_endpoint => "elasticbeanstalk.#{region}.amazonaws.com"
}
AWS.config(config)
class AWSContext
def self.service(name, klass)
define_method(name) do
@services[name] ||= klass.new
end
end
def initialize
@services = {}
end
service :cloud_formation, AWS::CloudFormation
service :elastic_beanstalk, AWS::ElasticBeanstalk
service :ec2, AWS::EC2
service :s3, AWS::S3
end
require 'pry'
Pry.config.prompt = [proc { "AWS> " }, proc { "AWS| " }]
AWSContext.new.pry
@trevorrowe
Copy link
Copy Markdown

Here is another version to play with. This adds a colored logger by default and makes it easy to enable a debug mode which prints HTTP wire traces.

#!/usr/bin/env ruby

# silence warnings from pry, these are normally autoloaded by aws-sdk
require 'nokogiri'
require 'json'
require 'uuidtools'

require 'aws-sdk'
require 'logger'
require 'pry'

AWS.config(
  logger: ENV['NO_LOG'] ? nil : Logger.new($stdout),
  log_formatter: AWS::Core::LogFormatter.send(ENV['LOGGER'] || 'colored'),
  http_wire_trace: !!ENV['DEBUG'] || $DEBUG)

Pry.config.prompt = [proc { "AWS> " }, proc { "AWS| " }]

AWS.pry

@mdub
Copy link
Copy Markdown
Author

mdub commented Jun 3, 2013

Nice, thanks!

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