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 / gist:49bfb9d59f83ad450a9e
Created March 28, 2015 03:11
Demonstration of using pre-signed GET url to download a server-side-encrypted with customer key from Amazon S3
require 'aws-sdk'
require 'openssl'
bucket_name = 'bucket-name'
object_key = 'object-key'
# patch for `aws-sdk` v2 gem (needed for versions <= v2.0.33, patch will be applied shortly to master)
class Aws::Signers::V4
def presigned_url(request, options = {})
now = Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
import java.nio.file.Paths;
public class TransferManagerUploadExample {
private static final String BUCKET = <bucket>;
private static final String KEY = <key>;
private static final String FILE_PATH = <path>;
public static void main(String[] args) throws InterruptedException {
@trevorrowe
trevorrowe / client.rb
Created June 29, 2015 21:03
Ruby Net::HTTP Expect-100 continue PUT bug
require 'net/http'
require 'logger'
req = Net::HTTP::Put.new('/', { 'expect' => '100-continue' })
req.body = 'data'
http = Net::HTTP.new('localhost', 3000)
http.continue_timeout = 1
http.set_debug_output(Logger.new($stdout))
http.request(req)
@trevorrowe
trevorrowe / empty-example
Last active October 19, 2017 00:07
AWS SDK for Ruby v2 pluggable HTTP client example
#!/usr/bin/env ruby
require 'aws-sdk'
# This example produces empty http responses, but gives some general structure and guiance.
class DummyHttpHandler < Seahorse::Client::Handler
def call(context)
context.http_request.endpoint # HTTP or HTTPS URI
@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
class Tree
def initialize(name = nil, path = '')
@name = name
@path = path
@folders = {}
@files = []
end
attr_reader :name, :path, :folders, :files
namespace :benchmarks do
namespace :dynamodb do
task :get_item do
require 'benchmark'
require 'aws-sdk'
table_name = 'aws-sdk-core-benchmarks'
params = {
@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
@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 / instances.rb
Created November 20, 2015 23:09
Listing EC2 instances
# using EC2 client
ec2 = Aws::EC2::Client.new
ec2.describe_instances.each_page do |resp|
resp.reservations.each do |reservation|
reservation.instances.each do |intsance|
puts instance.instance_id
end
end
end