Class: Aws::S3::Presigner

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-core/s3/presigner.rb

Overview

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")

Defined Under Namespace

Classes: PresignHandler

Constant Summary collapse

ONE_WEEK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

60 * 60 * 24 * 7
FIFTEEN_MINUTES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

60 * 15

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Presigner

Returns a new instance of Presigner.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :client (Client)

    Optionally provide an existing S3 client



21
22
23
# File 'lib/aws-sdk-core/s3/presigner.rb', line 21

def initialize(options = {})
  @client = options[:client] || Aws::S3::Client.new
end

Instance Method Details

#presigned_url(method, params = {}) ⇒ Object

Parameters:

  • method (Symbol)

    Symbolized method name of the operation you want to presign.

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :expires_in (Integer) — default: 900

    The number of seconds before the presigned URL expires. Defaults to 15 minutes.

Raises:

  • (ArgumentError)

    Raises an ArgumentError if ‘:expires_in` exceeds one week.



34
35
36
37
38
39
40
41
# File 'lib/aws-sdk-core/s3/presigner.rb', line 34

def presigned_url(method, params = {})
  request = @client.build_request(method, params)
  request.handle(PresignHandler, step: :sign, priority: 99)
  expires_in = params.delete(:expires_in) || FIFTEEN_MINUTES
  validate_expires_in_header(expires_in)
  request.context[:presigned_expires_in] = expires_in
  request.send_request.data
end