Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get JSON response using AWS presigned url

I'm able to generate a presigned url like so

import boto3
s3 = boto3.client('s3')
url = s3.generate_presigned_url( ClientMethod='list_objects', Params={'Bucket':'bucket-name'} )

# now get the listing
import requests
r = requests.get(url)

# r.status_code is 200
# Problem:  r.text output is in XML format

When I do a direct call s3.list_objects(Bucket='bucket-name') then I get the response in JSON. There is no option to specify content type when generating the url. I've tried updating the headers of the request with accept: application/json, but that results in a "SignatureDoesNotMatch" error from AWS.

Ultimately I will be using the URL client-side with javascript. This example is just to illustrate the problem.

How do I get the response in JSON when using a presigned URL (preferably using boto)? Seems like it should be possible.

like image 705
lps Avatar asked May 23 '16 23:05

lps


1 Answers

There is no way to do this, S3 only returns XML. boto3 has response parsing that converts it into a dictionary for ease of use.

like image 176
Jordon Phillips Avatar answered Sep 22 '22 23:09

Jordon Phillips