Skip to content

Instantly share code, notes, and snippets.

Trevor Rowe trevorrowe

Block or report user

Report or block trevorrowe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Java Example
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 / empty-example
Last active Oct 19, 2017
AWS SDK for Ruby v2 pluggable HTTP client example
View empty-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 / instances.rb
Created Nov 20, 2015
Listing EC2 instances
View instances.rb
# 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
@trevorrowe
trevorrowe / progress.rb
Created Sep 14, 2015
Tracking progress of a file upload using v2 of the aws-sdk gem
View progress.rb
require 'aws-sdk'
require 'pathname'
class ProgressIO
def initialize(io)
@io = io
@bytes_read = 0
@listeners = []
end
@trevorrowe
trevorrowe / client.rb
Created Jun 29, 2015
Ruby Net::HTTP Expect-100 continue PUT bug
View client.rb
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 / gist:bb041b0d7b57df239d43
Created Jun 29, 2015
Expect-100 continue PUT bug - sever
View gist:bb041b0d7b57df239d43
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 / gist:de95d25baa0d472d71da
Created Jun 29, 2015
Expect-100 continue PUT bug - client
View gist:de95d25baa0d472d71da
# This example server accepts a simple PUT request with the 'Excpect: 100-continue'
# header. It alternates between the following two responses:
#
# * 100 Continue, accepting the body, then 200 OK
# * 403 Forbidden, not accepting the body
#
require 'socket'
server = TCPServer.new('localhost', 3000)
@trevorrowe
trevorrowe / gist:8162733833c90491a9b3
Last active Aug 29, 2015
Plugin that conditionally raises response errors
View gist:8162733833c90491a9b3
class ConditionalRaisePlugin < Seahorse::Client::Plugin
class Handler < Seahorse::Client::Handler
def call(context)
response = @handler.call(context)
conditional_raise(response.error, context.config.errors_to_ignore)
response
end
View gist:61dd9f550445bc32b3b7
class ProgressIO
def initialize(io)
@io = io
end
def read(bytes = nil, output_buffer = nil)
puts bytes
@io.read(bytes, output_buffer)
end
View gist:c307eb86f59a22fd32ff
pattern = "[aws] [:client_class] operation=:operation duration=:time retries=:retries error=:error_class\n"
Aws.config[:log_formatter] = Seahorse::Client::Logging::Formatter.new(pattern)
# success
[aws] [Aws::S3::Client] operation=list_buckets duration=0.602057 retries=0 error=
# error
[aws] [Aws::S3::Client] operation=head_bucket duration=1.100552 retries=0 error=Aws::S3::Errors::Forbidden
You can’t perform that action at this time.