0

The permissions for Sentinel2 L1C changed today

https://www.sentinel-hub.com/faq/how-will-access-permission-changes-aws-bucket-affect-users-accessing-data-directly-non-sentinel#

How can I send a 'requester pays' header when using boto3?

My previous code (below) which worked previously is now hitting a 403

  s3 = boto3.resource('s3')
  bucket = s3.Bucket(bucket_name)
  bucket.download_file(key, fpath)
2

Here is a sample code that should work (given that your config and credentials are saved in ~/.aws)

import boto3

s3_client = boto3.Session().client('s3')
response = s3_client.get_object(Bucket='sentinel-s2-l1c',
                                Key='tiles/7/W/FR/2018/3/31/0/B01.jp2', 
                                RequestPayer='requester')
response_content = response['Body'].read()

with open('./B01.jp2', 'wb') as file:
    file.write(response_content)

I extracted this code from what we have implemented in sentinelhub Python package. The full code is available here and is basically also handling multithreaded download and certain errors which can occur during download.

By the way, sentinelhub supports download of Sentinel-2 L1C and L2A data from AWS: examples.

  • 1
    Hours googling, hours I say, until I hit upon the right search terms to bring me here! – Blazinator Sep 7 '18 at 17:55
0

I also found an alternative, run the s3api cli as a subprocess. A working shell command:

$ aws s3api get-object --bucket sentinel-s2-l1c --key tiles/10/T/DM/2018/8/1/0/B801.jp2 --request-payer requester /home/sam/Desktop/B01.jp2

and the python3.6 equivalent:

import subprocess

bucket = 'sentinel-s2-l1c'
band = 'B01'

key = f'tiles/10/T/DM/2018/8/1/0/{band}.jp2'
outfile = f'/home/sam/Desktop/{band}.jp2'

subprocess.run(['aws', 's3api', 'get-object', '--bucket', bucket, '--key', key, '--request-payer', 'requester', outfile])

This will work as long as ~/.aws/config is setup, i.e.

$ aws configure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.