[GIS] Reading S3 Sentinel-2 image files with rasterio

amazon-web-servicespythonrasterioremote sensingsentinel-2

I am currently experiencing an 'Access Denied' error after using rasterio to open the Sentinel-2 AWS .jp2 image files (currently hosted by Sinergise and can be found here).

My code looks like this:

import rasterio

access_key = '*****************'
secret_access_key = '***********************'
region_name = 'eu-central-1'

Session = rasterio.env.Env(aws_access_key_id=access_key,
             aws_secret_access_key=secret_access_key,
             region_name=region_name)

url = 's3://sentinel-pds/tiles/10/S/DG/2015/12/7/0/B01.jp2'

with Session:
    with rasterio.open(url) as dataset:
            print dataset

The response is:

---------------------------------------------------------------------------
CPLE_AWSAccessDenied                      Traceback (most recent call last)
<ipython-input-1-4f6da7274649> in <module>()
     12 
     13 with Session:
---> 14     with rasterio.open(url) as dataset:
     15         print dataset

/Users/Barney/anaconda/lib/python2.7/site-packages/rasterio/__init__.pyc in open(path, mode, driver, width, height, count, crs, transform, dtype, nodata,  **kwargs)
    191         raise ValueError(
    192             "mode string must be one of 'r', 'r+', or 'w', not %s" % mode)
--> 193     s.start()
    194     return s
    195 

rasterio/_base.pyx in rasterio._base.DatasetReader.start (rasterio/_base.c:2847)()

rasterio/_base.pyx in rasterio._base.DatasetReader.start (rasterio/_base.c:2799)()

rasterio/_err.pyx in rasterio._err.CPLErrors.check (rasterio/_err.c:1773)()

CPLE_AWSAccessDenied: Access Denied 

I'm unsure if I am using rasterio aws environments correctly, is the aws session token key required even if the secret and access keys are provided? I should also add that this function works correctly if provided with a Landsat-8 url (i.e. http://landsat-pds.s3.amazonaws.com/L8/139/045/LC81390452014295LGN00/LC81390452014295LGN00_B1.TIF)

Versions (installed through Anaconda):

rasterio – 0.36.0

python – 2.7

Sorry if the above is vague. My questions would be – why does this work for Landsat-8 but not Sentinel-2? How can rasterio be used to open Sentinel-2 AWS data?

Best Answer

I believe you are using the wrong bucket name. It should be s3://sentinel-s2-l1c, not s3://sentinel-pds

Try:

url = 's3://sentinel-s2-l1c/tiles/10/S/DG/2015/12/7/0/B01.jp2'

See more info here: http://sentinel-pds.s3-website.eu-central-1.amazonaws.com/ and https://aws.amazon.com/public-datasets/sentinel-2/