Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download Object from Pre-signed URL #463

Closed
relvacode opened this issue Dec 9, 2015 · 12 comments
Closed

Download Object from Pre-signed URL #463

relvacode opened this issue Dec 9, 2015 · 12 comments
Labels
guidance Question that needs advice or information.

Comments

@relvacode
Copy link

Is there functionality to download from a pre-signed URL?

I would like to use the nice concurrency features of the S3 downloader, except this requires full knowledge of the bucket auth details which my client doesn't know.

Perhaps I should use another library for concurrent generic file download? If so can you recommend one?

@relvacode relvacode changed the title Download Object form Pre-signed URL Download Object from Pre-signed URL Dec 9, 2015
@jasdel jasdel added the guidance Question that needs advice or information. label Dec 10, 2015
@jasdel
Copy link
Contributor

jasdel commented Dec 10, 2015

Hi @relvacode the SDK doesn't currently posse the ability to download concurrently from a presigned URLs. Since the original presigned URL is generated for a specific operation and request it cannot be split into multiple byte ranges.

If you're the one generating the presigned URLs you could use the S3.GetObject operations with a range requests to generate your presigned URLs for the object you're wanting to download concurrently. You could distribute these multiple presigned URLs to your client and they would be able to split the request into multiple parts.

@jasdel
Copy link
Contributor

jasdel commented Jan 7, 2016

HI @relvacode I'm going to close this issue for now. Please open it back up if you have any more question, or we can help clarify the issue you're facing.

@jasdel jasdel closed this as completed Jan 7, 2016
@ghost
Copy link

ghost commented Apr 27, 2017

Hi @jasdel - Reviving this old thread but can you help me understand how I can generate multiple presigned URLs from the GetObject API ?

@jasdel
Copy link
Contributor

jasdel commented Apr 27, 2017

Hi @ananddhandhania the best way to get a presigned URL for the GetObject API call is to use the Request.Presign method of a Request.

svc := s3.New(sess)

req, _ := svc.GetObjectRequest(&s3.GetObjectInput{
    Bucket: aws.String(myBucket),
    Key: aws.String(myKey),
})

urlStr, signedHeaders, err := req.PresignRequest(15 * time.Minute)

Once you have the URL string you can share the presigned URL and any HTTP client can use the URL to make a the request to the S3 service until the 15 minutes have expired.

In addition the signedHeaders returned need to also be set by the client that will make the request with the URL to ensure the request's signature is validated correctly.

@ghost
Copy link

ghost commented May 2, 2017

Thanks @jasdel. Is this something unique to S3 sdk for go ?
I can't see something similar for java sdk.

@jasdel
Copy link
Contributor

jasdel commented May 2, 2017

@ananddhandhania Each SDK should have a way to create presigned URLs for API operations. For the AWS SDK for Java checkout this document, http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURLJavaSDK.html

@ghost
Copy link

ghost commented May 2, 2017

Another approach I would like to share is this. As you can see, from a single presigned url, we can provide the bytes range. This means we can do a parallel download with raw curl by passing in the image bytes range in the http request header. Isn't this better than generating multiple presigned urls?

f45c89a59d13:~ ananddh$ curl -v -X GET -H "range: bytes=27-300" 'https://random-presigned-url-bucket.s3.amazonaws.com/very_large_image.jpg?AWSAccessKeyId=AADDSADASDASDAS&Expires=1493783501&x-amz-security-token=DADAsdasdsaasASDK3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDIRP9SbovN9s5vwG0SLTAaaag1edYamrIqoTZX340jaBixD6x3fyyZVtFKvTD1Gg3U3jornraaFXbyrqBxS0Vu5DeG%2BwWazISVEvyQt7gO6CogaN41KcylAO9y1qAPsGwsrw3P3UZa8u7n3XCmMx%2BOurWnLGeuCgQrdWbVhlOEQwYqBZGW%2BbPx90PR3LBjjuADThD2Qzfno%2B67ciTX3W1YLKCMmuhNxJonORSFE2GrjDlDqSasnD%2FsCS3pt0NTTMW04C8AxSXHP%2FwvQUQIaHk7djrs57ebx2xIUaP3cdN5VL8usoh72jyAU%3D&Signature=9k8a572lTpkipLu%2B8t%2FTLzoUSgE%3D'

  • Trying 52.216.1.64...
  • Connected to random-presigned-url-bucket.s3.amazonaws.com (52.216.1.64) port 443 (#0)
  • TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  • Server certificate: *.s3.amazonaws.com
  • Server certificate: DigiCert Baltimore CA-2 G2
  • Server certificate: Baltimore CyberTrust Root

GET /very_large_image.jpg?AWSAccessKeyId=ASIAJ7C2CSNM4SJX4PHA&Expires=1493783501&x-amz-security-token=FQoDYXdzEK3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDIRP9SbovN9s5vwG0SLTAaaag1edYamrIqoTZX340jaBixD6x3fyyZVtFKvTD1Gg3U3jornraaFXbyrqBxS0Vu5DeG%2BwWazISVEvyQt7gO6CogaN41KcylAO9y1qAPsGwsrw3P3UZa8u7n3XCmMx%2BOurWnLGeuCgQrdWbVhlOEQwYqBZGW%2BbPx90PR3LBjjuADThD2Qzfno%2B67ciTX3W1YLKCMmuhNxJonORSFE2GrjDlDqSasnD%2FsCS3pt0NTTMW04C8AxSXHP%2FwvQUQIaHk7djrs57ebx2xIUaP3cdN5VL8usoh72jyAU%3D&Signature=9k8a572lTpkipLu%2B8t%2FTLzoUSgE%3D HTTP/1.1
Host: random-presigned-url-bucket.s3.amazonaws.com
User-Agent: curl/7.43.0
Accept: /
range: bytes=27-300

< HTTP/1.1 206 Partial Content
< x-amz-id-2: CMU8IDkjFAKF2qR/zqMQ9lP11bHiEMdhChKz2EuxsCcIjo6Nd7khGUrqo0Eq6eyV94+ggY+UH8k=
< x-amz-request-id: 56F1961D023C59BD
< Date: Tue, 02 May 2017 19:34:36 GMT
< Last-Modified: Wed, 09 Nov 2016 01:27:25 GMT
< ETag: "7a4c42317eaf4754e5217c1361c70dd5-9"
< x-amz-version-id: null
< Accept-Ranges: bytes
< Content-Range: bytes 27-300/71590911
< Content-Type: image/jpeg
< Content-Length: 274
< Server: AmazonS3
<

  • Connection #0 to host random-presigned-url-bucket.s3.amazonaws.com left intact
    Or????(1?2-??'-??'Adobe Photoshop CS5 Macintosh2012:03:28 12:46:48????.?

@jasdel
Copy link
Contributor

jasdel commented May 2, 2017

For download using a single presigned URL multiple times is a great way to go. The only consideration to make is that the presigned URL's expiration time is long enough that for large objects the presigned URL will not expire.

@tjumlani
Copy link

Can an object have multiple presigned urls ?

@jasdel
Copy link
Contributor

jasdel commented Dec 11, 2017

Hi @tjumlani, yes, a presigned URL is just a reference a client can use to get/put an object. There is no limit to the number of presigned URLs that can reference a single object.

@tjumlani
Copy link

Thanks. I experimented on that a moment ago and has been validated by your answer.

@evdokim
Copy link

evdokim commented Mar 25, 2020

Sorry for opening an old thread, but I discovered that Java SDK have such functionality in their TransferManager: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferManager.html#download-com.amazonaws.services.s3.model.PresignedUrlDownloadRequest-java.io.File-

I am wondering is there a plan to support it in aws-sdk-go as well?

skotambkar added a commit to skotambkar/aws-sdk-go that referenced this issue May 20, 2021
Updates the wafregional and dynamodbstreams API clients to include all API operations, and types that were previously shared between waf and dynamodb API clients respectively. This update ensures that all API clients include all operations and types needed for that client, and shares no types with another client package.

To migrate your applications to use the updated wafregional and dynamodbstreams you'll need to update the package the impacted type is imported from to match the client the type is being used with.
skotambkar pushed a commit to skotambkar/aws-sdk-go that referenced this issue May 20, 2021
Breaking Change
---
* `service`: Add generated service for wafregional and dynamodbstreams aws#463
  * Updates the wafregional and dynamodbstreams API clients to include all API operations, and types that were previously shared between waf and dynamodb API clients respectively. This update ensures that all API clients include all operations and types needed for that client, and shares no types with another client package.
  * To migrate your applications to use the updated wafregional and dynamodbstreams you'll need to update the package the impacted type is imported from to match the client the type is being used with.
* `aws`: Context has been added to EC2Metadata operations.([aws#461](aws/aws-sdk-go-v2#461))
  * Also updates utilities that directly or indirectly depend on EC2Metadata client. Signer utilities, credential providers now take in context.
* `private/model`: Add utility for validating shape names for structs and enums for the service packages ([aws#471](aws/aws-sdk-go-v2#471))
  * Fixes bug which allowed service package structs, enums to start with non alphabetic character
  * Fixes the incorrect enum types in mediapackage service package, changing enum types __AdTriggersElement, __PeriodTriggersElement to AdTriggersElement, PeriodTriggersElement respectively.
* `aws`: Client, Metadata, and Request structures have been refactored to simplify the usage of resolved endpoints ([aws#473](aws/aws-sdk-go-v2#473))
  * `aws.Client.Endpoint` struct member has been removed, and `aws.Request.Endpoint` struct member has been added of type `aws.Endpoint`
  * `aws.Client.Region` structure member has been removed

Services
---
* Synced the V2 SDK with latest AWS service API definitions.

SDK Features
---
* `aws`: `PartitionID` has been added to `aws.Endpoint` structure, and is used by the endpoint resolver to indicate which AWS partition an endpoint was resolved for ([aws#473](aws/aws-sdk-go-v2#473))
* `aws/endpoints`: Updated resolvers to populate `PartitionID` for a resolved `aws.Endpoint` ([aws#473](aws/aws-sdk-go-v2#473))
* `service/s3`: Add support for Access Point resources
  * Adds support for using Access Point resource with Amazon S3 API operation calls. The Access Point resource are identified by an Amazon Resource Name (ARN).
  * To make operation calls to an S3 Access Point instead of a S3 Bucket, provide the Access Point ARN string as the value of the Bucket parameter. You can create an Access Point for your bucket with the Amazon S3 Control API. The Access Point ARN can be obtained from the S3 Control API. You should avoid building the ARN directly.

SDK Enhancements
---
* `internal/sdkio`: Adds RingBuffer data structure to the sdk [aws#417](aws/aws-sdk-go-v2#417)
  * Adds an implementation of RingBuffer data structure which acts as a revolving buffer of a predefined length. The RingBuffer implements io.ReadWriter interface.
  * Adds unit tests to test the behavior of the ring buffer.
* `aws/ec2metadata`: Adds support for EC2Metadata client to use secure tokens provided by the IMDS ([aws#453](aws/aws-sdk-go-v2#453))
  * Modifies EC2Metadata client to use request context within its operations ([aws#462](aws/aws-sdk-go-v2#462))
  * Reduces the default dialer timeout and response header timeout to help reduce latency for known issues with EC2Metadata client running inside a container
  * Modifies and adds tests to verify the behavior of the EC2Metadata client.
* `service/dynamodb/dynamodbattribute`: Adds clarifying docs on dynamodbattribute.UnixTime ([aws#464](aws/aws-sdk-go-v2#464))
* `example/service/sts/assumeRole`: added sts assume role example ([aws#224](aws/aws-sdk-go-v2#224))
  * Fixes [aws#157](aws/aws-sdk-go-v2#157) by adding an example for Amazon STS assume role to retrieve credentials.

SDK Bugs
---
* `service/dynamodb/dynamodbattribute`: Fixes a panic when decoding into a map with a key string type alias. ([aws#465](aws/aws-sdk-go-v2#465))
  * Fixes [aws#410](aws/aws-sdk-go-v2#410),  by adding support for keys that are string aliases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

4 participants