【发布时间】:2021-09-29 21:37:57
【问题描述】:
我想从 Amazon 的 Copernicus Digital Elevation Model 存储桶中获取指向云优化 geoTIFF 的 URL。
安装boto3(带pip3 install boto3)后,我靠this answer到问题Can I use boto3 anonymously?下载单个文件:
import boto3
from botocore import UNSIGNED
from botocore.client import Config
s3 = boto3.client('s3', region_name='eu-central-1', config=Config(signature_version=UNSIGNED))
然后我查询存储桶中的对象列表,使用this answer的第二行到问题Use boto3 to download from public bucket:
objects = s3.list_objects(Bucket='copernicus-dem-30m')
然后我访问objects['Contents']中的一个值,例如第一个(即索引0):
key = objects['Contents'][0]['Key']
key 现在是:
Copernicus_DSM_COG_10_N00_00_E006_00_DEM/Copernicus_DSM_COG_10_N00_00_E006_00_DEM.tif
我通过以下方式下载此文件:
s3.download_file('copernicus-dem-30m', key, key.split('/')[-1])
我怎样才能生成一个 URL,而不是下载,然后我可以使用它来下载文件,也许使用 wget 或只是将其粘贴到浏览器?
上面显示的这段代码基于线程:How to get Copernicus DEM GeoTIFFs for a bounding box using Python。
【问题讨论】:
标签: python amazon-web-services amazon-s3