This is the script which I wrote for downloading object from S3 via a pre-signed url:
import boto3
import os
AWS_ACCESS_KEY_ID = '<>'
AWS_SECRET_ACCESS_KEY = '<>'
region = '<>'
session = boto3.Session(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, region_name = region)
s3 = session.client('s3')
url = s3.generate_presigned_url('get_object', Params = {'Bucket': '<>', 'Key': '<>.json'}, ExpiresIn = 100)
print url
os.system('curl ' + url)
From this, I am able to get the url, but the os.system command is giving me the following error:
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>...</RequestId><HostId>...</HostId></Error>
But, when I directly try the url in my browser, it is downloading the file.
So, what did I do wrong here? How do I download the file via the Python script?
Surround the url with quotes (") when making the curl request.
os.system('curl "'+ url + '"')
To save it in a file, use
os.system('curl -o /tmp/file.txt "'+ url + '"')
Or, Use the requests module to make the GET
import requests
response = requests.get(url)