Skip to content

Instantly share code, notes, and snippets.

View trevorrowe's full-sized avatar

Trevor Rowe trevorrowe

  • Amazon.com
  • Seattle, WA
View GitHub Profile
@trevorrowe
trevorrowe / Installing aws-sdk gem on EC2
Created February 20, 2012 17:58
Installing the aws-sdk gem on EC2 (using the Amazon Linux AMI)
sudo yum install -y gcc make \
libxml2 libxml2-devel libxslt libxslt-devel \
rubygems ruby-devel
sudo gem install nokogiri -- --with-xml2-lib=/usr/local/lib \
--with-xml2-include=/usr/local/include/libxml2 \
--with-xslt-lib=/usr/local/lib \
--with-xslt-include=/usr/local/include
sudo gem install aws-sdk --no-ri --no-rdoc
@trevorrowe
trevorrowe / debug handler example
Created March 22, 2012 21:34
Wrapping the aws-sdk http handler to view raw http requests and responses
# build a dummy http handler that extends the default handler
# that outputs the request body before making the request (via super)
# then check the response body
# req is a AWS::Core::Http::Request object
# resp is a AWS::Core::Http::Response object
default_handler = AWS.config.http_handler
debug_handler = AWS::Core::Http::Handler.new(default_handler) do |req,resp|
puts "REQUEST BODY: #{req.body}"
super(req,resp)
@trevorrowe
trevorrowe / enable logging
Created March 22, 2012 21:45
Enabling logging in the aws-sdk gem
require 'aws-sdk'
require 'logger'
# configure a logger instance that logs to standard out,
# this could be a file, standard error, etc. The logger only
# needs to respond to #log and accept a severity and a message.
AWS.config(:logger => Logger.new($stdout))
# make a request to see the request logger
ec2 = AWS::EC2.new
@trevorrowe
trevorrowe / gist:7574548
Created November 21, 2013 01:31
Reproduces a bug with the AWS::S3::CipherIO class.
require 'aws-sdk'
require 'openssl'
class DotStream
def initialize(size)
@size = size
@bytes_left = size
end
@trevorrowe
trevorrowe / CipherIO bug case
Created November 21, 2013 01:31
A simple repo case for a bug in the Ruby SDK CipherIO class.
require 'aws-sdk'
require 'openssl'
class DotStream
def initialize(size)
@size = size
@bytes_left = size
end
namespace :benchmarks do
namespace :dynamodb do
task :get_item do
require 'benchmark'
require 'aws-sdk'
table_name = 'aws-sdk-core-benchmarks'
params = {
class Tree
def initialize(name = nil, path = '')
@name = name
@path = path
@folders = {}
@files = []
end
attr_reader :name, :path, :folders, :files
cf = Aws::CloudFront::Client.new
resp = cf.create_distribution(
distribution_config: {
caller_reference: Time.now.to_i.to_s,
aliases: {
quantity: 0
},
default_root_object: '',
origins: {
@trevorrowe
trevorrowe / gist:93c112eddc27182c9d96
Created October 15, 2014 23:34
Subscribing a queue to a topic
require 'aws-sdk-v1'
queue = AWS::SQS.new.queues['queue-arn']
topic = AWS::SNS.new.topics['topic-arn']
# this will modify the queue policy to allow the topic to send messages
topic.subscribe(queue)
@trevorrowe
trevorrowe / gist:2470ceb420edb322a178
Created January 29, 2015 21:47
A simple **untested** extraction from the V1 SDK for Ruby from AWS::SQS::Queue#poll.
# A simple extraction from the V1 SDK for Ruby from AWS::SQS::Queue#poll.
# No effort was made to test this code.
#
# @example Basic Usage
#
# poller = QueuePoller.new(queue_url)
# poller.poll { |msg| puts msg.body}
#
# @example Customized API client
#