Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon AWS S3 signed URL via Wget

I am able to create an Amazon S3 signed URL for a bucket in my account from which I can download and upload via the Amazon AWS CLI.

I have created the Amazon S3 URL as follows:

from boto.s3.connection import S3Connection
key = os.environ['aws_access_key_id']
secret = os.environ['aws_secret_access_key']
c = S3Connection(key,secret,is_secure=False)
bucket = c.get_bucket('my-bucket')
bktkey = bucket.get_key('stuff.tar.gz')
seconds=60*60*12
url2 = bktkey.generate_url(expires_in=seconds)
print '%s' %url2

Using url2 and copy pasting it in Chrome, I get stuff.tar.gz downloaded.

But when I use Wget like so

wget <whatever is in url2>

I get the following exception,

HTTP request sent, awaiting response... 403 Forbidden
2015-12-04 20:48:57 ERROR 403: Forbidden.

Why is Wget failing where Chrome and Firefox are successful in downloading using the signed Amazon S3 URL?

like image 438
mg03 Avatar asked Dec 05 '15 05:12

mg03


People also ask

How do I get pre-signed URL S3?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for. In the Objects list, select the object that you want to create a presigned URL for.

What is signed URL in S3?

S3 pre-signed URLs are a form of an S3 URL that temporarily grants restricted access to a single S3 object to perform a single operation — either PUT or GET — for a predefined time limit. To break it down: It is secure — the URL is signed using an AWS access key.

Is S3 Presigned URL safe?

Pre-signed URLs can be generated for an S3 object, allowing anyone who has the URL to retrieve the S3 object with an HTTP request. Not only is this more secure due to the custom nature of the URL, but the available options also allow you to set an expiration on the URL, the default being one hour.


1 Answers

I had the same issue. The fix is to use quotes:

wget -O test.tar.gz "https://bucket.s3.amazonaws.com/app1/10/10.2/test.tar.gz?Signature=hgbdhjJHGK&Expires=1454446963&AWSAccessKeyId=AAAAAAAAA"
like image 62
user3323536 Avatar answered Sep 22 '22 12:09

user3323536