-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathboto_request.py
More file actions
45 lines (38 loc) · 1.53 KB
/
boto_request.py
File metadata and controls
45 lines (38 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import boto3
from botocore.client import Config
import sys
import time
access_key = "0555b35654ad1656d804"
secret_key = "h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=="
endpoint_url = "http://127.0.0.1:8000"
is_secure = False
#boto3.set_stream_logger(name='botocore')
client = boto3.client(service_name='s3', aws_access_key_id=access_key, aws_secret_access_key=secret_key,
endpoint_url=endpoint_url,
use_ssl=is_secure,
verify=False,
config=Config(signature_version='s3v4'))
obj_name = sys.argv[2]
bucket_name = "my_bucket"
f = open(obj_name, 'r')
data = f.read()
if sys.argv[1] == "put":
print ("Putting Object")
client.create_bucket(Bucket=bucket_name)
res = client.put_object(Bucket=bucket_name, Key=obj_name, Body=data)
print (res)
if sys.argv[1] == "get":
print ("Getting Object")
t1 = time.time()
res = client.get_object(Bucket=bucket_name, Key=obj_name)
print ("len of response:" +str(len(res['Body'].read())))
print ("It took:", time.time()-t1)
if sys.argv[1] == "prefetch":
print ("Getting Object")
header = {'prefetch': 'value'}
set_header = (lambda **kwargs: kwargs['params']['headers'].update(header))
client.meta.events.register('before-call.s3.GetObject', set_header)
res = client.get_object(Bucket=bucket_name, Key=obj_name)
print (res)
#print (res['Body'].read())
print ("len of response:" +str(len(res['Body'].read())))