-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_signed_url_list.py
More file actions
66 lines (47 loc) · 1.64 KB
/
create_signed_url_list.py
File metadata and controls
66 lines (47 loc) · 1.64 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 17 16:24:00 2019
@author: Rohit Malyala
"""
import boto3
import csv
"""
The contents of this comment section should ideally be hidden away in a
credentials file. They are kept open here for the sake of pointing out
how another user might put use their own accounts for the purpose.
Uncomment this file to run the python script on any computer.
region = 'us-east-1'
aws_access_key_id = 'XXXXXXXXXXXXXXXXXX'
aws_secret_access_key = 'XXXXXXXXXXXXXXXXXXXXX+XXXX'
"""
session = boto3.session.Session(region_name=region)
s3client = session.client('s3', config= boto3.session.Config(signature_version='s3v4'))
# List all the buckets with the account
bucket_list = s3.list_buckets()
print('Existing Buckets: ')
for bucket in bucket_list['Buckets']:
print(f' {bucket["Name"]}')
# list objects
object_list = s3.list_objects(Bucket='lithotripsystonefinder')
with open('input.csv', 'w', newline='') as csvFile:
writer = csv.writer(csvFile)
for key in object_list['Contents']:
# s3client.get_object(Bucket='lithotripsystonefinder', Key=key['Key'])
presigned_url = s3client.generate_presigned_url('get_object',
Params={
'Bucket': "lithotripsystonefinder",
'Key': key['Key'],
},
ExpiresIn=604800,
)
writer.writerow([presigned_url])
# replace the header [0] slot with "input_url"
f = open('input.csv', 'r', newline = '')
reader = csv.reader(f)
mylist = list(reader)
f.close()
mylist[0] = ['image_url']
my_new_list = open('input.csv', 'w', newline = '')
csv_writer = csv.writer(my_new_list)
csv_writer.writerows(mylist)
my_new_list.close()