How to download EODATA file using boto3 on Creodias

LEGACY ARTICLE

This article is marked as a legacy document and may not reflect the latest information. Please refer to the following article: How to access EODATA using boto3 on Creodias

Download particular Landsat-5 image.

Prerequisites

No. 1 Ubuntu virtual machine and terminal access

Use an existing Ubuntu VM or create one and connect to it using How to create a Linux VM and access it from Windows desktop on Creodias or How to create a Linux VM and access it from Linux command line on Creodias. Run the commands below in the VM’s terminal. The VM needs access to the eodata network or the project network whose name starts with eodata_.

No. 2 Python environment

To avoid package conflicts, we recommend installing boto3 in a virtual environment. Create and activate it using How to install Python virtualenv or virtualenvwrapper on Creodias. If you choose the system-wide installation below instead, you need sudo privileges on the VM.

No. 3 EODATA access key and secret key

Obtain the key pair using How to get credentials used for accessing EODATA on a cloud VM on Creodias. Alternatively, open Configuration → EODATA Access in the dashboard and follow Obtain S3 credentials for EODATA Access from Creodias Dashboard to create a key pair. Keep both values ready for the access_key and secret_key variables in the script.

Install boto3

Install boto3 with the command that matches your setup:

  • If you are using an activated virtual environment:

    (myvenv) eouser@vm01:~$ python -m pip install boto3
    
  • If you want to install boto3 system-wide:

    eouser@vm01:~$ sudo apt install python3-boto3
    

Script for downloading one .png file

In the code below, replace the contents of the access_key variable with your access key and the contents of the secret_key variable with your secret key, respectively.

The output filename does not convert the downloaded data. Keep the .png extension for this PNG file.

These examples use the same EODATA endpoint in every Creodias region.

import boto3
access_key='YOUR ACCESS KEY'
secret_key='YOUR SECRET KEY'
key='Landsat-5/TM/L1T/2011/11/16/LS05_RMPS_TM__GTC_1P_20111116T100042_20111116T100111_147386_0194_0035_4BF1/LS05_RMPS_TM__GTC_1P_20111116T100042_20111116T100111_147386_0194_0035_4BF1.BP.PNG'
host='https://eodata.cloudferro.com'
s3=boto3.resource('s3',aws_access_key_id=access_key,
aws_secret_access_key=secret_key, endpoint_url=host,)

bucket=s3.Bucket('eodata')

bucket.download_file(key, '/home/eouser/image.png')

Save your file with .py extension and run with the ‘python3 <filename.py>’ command in your terminal. For example:

(boto3) eouser@vm01:~$ python3 eodownload.py

And here’s result:

(boto3) eouser@vm01:~$ python3 eodownload.py
(boto3) eouser@vm01:~$ ls
eodownload.py  image.png
../_images/image1.png

Downloaded image

What to do next

To browse EODATA folders and choose other files to download, follow How to access EODATA using boto3 on Creodias.