· 9 years ago · Oct 07, 2016, 04:24 PM
1#!/bash/sh
2
3bucket='my_bucket_name'
4file_path='path_to_my_file'
5resource="/${bucket}/${file_path}"
6# set url time to expire
7
8expires=$(date +%s -d '4000 seconds')
9stringtoSign="GETnnn${expires}n${resource}"
10s3Key='s3Key_here'
11s3Secret='s3SecretKey_here'
12
13signature=`echo -en ${stringtoSign} | openssl sha1 -hmac ${s3Key} -binary | base64`
14
15
16curl -G https://${bucket}.s3.amazonaws.com/${file_path}
17 --data AWSAccessKeyId=${s3Key}
18 --data Expires=${expires}
19 --data-urlencode Signature=${signature}
20
21import boto
22
23from boto.s3.key import Key
24
25
26KEY_ID = 'key_id'
27SECRET_KEY_ID = 'secret_key'
28SOURCE_FILE_NAME = 'path_to_file'
29DEST_FILE_NAME = 'file'
30BUCKET_NAME = 'my_bucket_name'
31
32boto.set_stream_logger('boto')
33conn = boto.connect_s3(KEY_ID, SECRET_KEY_ID)
34bucket = conn.get_bucket(BUCKET_NAME)
35
36# Get the Key object of the given key, in the bucket
37k = Key(bucket, SOURCE_FILE_NAME)
38
39# Get the contents of the key into a file
40k.get_contents_to_filename(DEST_FILE_NAME)