class Aws::S3::Presigner

Allows you to create presigned URLs for S3 operations.

Example Use:

signer = Aws::S3::Presigner.new
url = signer.presigned_url(:get_object, bucket: "bucket", key: "key")

Constants

FIFTEEN_MINUTES

@api private

ONE_WEEK

@api private

Public Class Methods

new(options = {}) click to toggle source

@option options [Client] :client Optionally provide an existing

S3 client
# File lib/aws-sdk-core/s3/presigner.rb, line 21
def initialize(options = {})
  @client = options[:client] || Aws::S3::Client.new
end

Public Instance Methods

presigned_url(method, params = {}) click to toggle source

@param [Symbol] method Symbolized method name of the operation you want

to presign.

@option params [Integer] :expires_in (900) The number of seconds

before the presigned URL expires. Defaults to 15 minutes.

@option params [Boolean] :secure (true) When `false`, a HTTP URL

is returned instead of the default HTTPS URL.

@raise [ArgumentError] Raises an ArgumentError if `:expires_in`

exceeds one week.
# File lib/aws-sdk-core/s3/presigner.rb, line 37
def presigned_url(method, params = {})
  expires_in = params.delete(:expires_in) || FIFTEEN_MINUTES
  scheme = params.delete(:secure) == false ? 'http' : 'https'

  request = @client.build_request(method, params)
  request.handle(PresignHandler, step: :sign, priority: 99)
  validate_expires_in_header(expires_in)
  request.context[:presigned_expires_in] = expires_in

  url = URI.parse(request.send_request.data)
  url.scheme = scheme
  url.to_s
end

Private Instance Methods

validate_expires_in_header(expires_in) click to toggle source
# File lib/aws-sdk-core/s3/presigner.rb, line 52
def validate_expires_in_header(expires_in)
  if(expires_in > ONE_WEEK)
    raise ArgumentError.new(
      "expires_in value of #{expires_in} exceeds one-week maximum"
    )
  end
end