Skip to content

71 aws s3

image image image

Loading geospatial datasets from an AWS S3 bucket

Uncomment the following line to install leafmap if needed.

1
# %pip install -U leafmap
1
# %pip install -U boto3

To Be able to run this notebook you'll need to have AWS credential available as environment variables. Uncomment the following lines to set the environment variables.

1
2
3
# import os
# os.environ["AWS_ACCESS_KEY_ID"] = "YOUR AWS ACCESS ID HERE"
# os.environ["AWS_SECRET_ACCESS_KEY"] = "YOUR AWS ACCESS KEY HERE"
1
import leafmap

In this example, we will use datasets from the Maxar Open Data Program on AWS.

1
2
BUCKET = "maxar-opendata"
FOLDER = "events/Kahramanmaras-turkey-earthquake-23/"

List all the datasets in the bucket. Specify a file extension to filter the results if needed.

1
2
items = leafmap.s3_list_objects(BUCKET, FOLDER, ext=".tif")
items[:10]

Visualize raster datasets from the bucket.

1
2
3
m = leafmap.Map()
m.add_cog_layer(items[2], name="Maxar")
m

Download a raster dataset from the bucket.

1
leafmap.s3_download_file(items[0], outfile="maxar.tif")

Download a list of raster datasets from the bucket.

1
leafmap.s3_download_files(items[:2], outdir="maxar")