Forum

Message Boards Message Boards

Back

Did you know #4 - How to access/list EO DATA using boto3?

Did you know #4 - How to access/list EO DATA using boto3?
earth-observation dias configuration creodias
Answer
3 October 2018 11:43
To use boto3 your virtual machine has to be initialized in project with eo data

We strongly recommend using virtualenv for isolating python packages. Configuration tutorial is presented below:https://creodias.eu/faq/-/asset_publisher/hv0ovzc1bXXS/content/how-to-install-python-virtualenv-virtualenvwrapper-?redirect=%2Ffaq&inheritRedirect=true 

If virtualenv is activated:
1
  $ pip install boto3
Or if we install package globally:
1
  $ sudo pip install boto3

Two examples for listing products: 


Client:

  • low-level service access
  • generated from service description
  • exposes botocore client to the developer
  • typically maps 1:1 with the service API
  • snake-cased method names (e.g. ListBuckets API => list_buckets method)
 
12345678910111213141516
#!/usr/bin/env python3
import boto3

access_key='anystring'
secret_key='anystring'

host='http://data.cloudferro.com'


s3=boto3.client('s3',aws_access_key_id=access_key,
aws_secret_access_key=secret_key, endpoint_url=host,)



for i in s3.list_objects(Delimiter='/', Bucket="DIAS", Prefix='Sentinel-2/MSI/L1C/2018/07/01/',MaxKeys=30000)['CommonPrefixes']:
        print(i)

Resource:

  • higher-level, object-oriented API
  • generated from resource description
  • uses identifiers and attributes
  • has actions (operations on resources)
  • exposes subresources and collections
 
12345678910111213141516
#/usr/bin/env python3
import boto3

access_key='anystring'
secret_key='anystring'

host='http://data.cloudferro.com'


s3=boto3.resource('s3',aws_access_key_id=access_key,
aws_secret_access_key=secret_key, endpoint_url=host,)

bucket=s3.Bucket('DIAS')

for obj in bucket.objects.filter(Prefix='Sentinel-2/MSI/L1C/2016/02/03/S2A_OPER_PRD_MSIL1C_PDMC_20160204T043037_R085_V20160203T203520_20160203T203520.SAFE/'):
     print('{0}:{1}'.format(bucket.name, obj.key))

Save your file with .py extension and run with the "python [filename.py]" command in your terminal.

For more information and picture demonstration, please visit: the FAQ section - https://creodias.eu/faq/-/asset_publisher/hv0ovzc1bXXS/content/how-to-list-eo-data-using-boto3-?redirect=%2Ffaq&inheritRedirect=true
0 (0 Votes)