遵循本教程:https ://www.usgs.gov/media/files/landsat-cloud-direct-access-requester-pays-tutorial
import boto3
import rasterio as rio
from matplotlib.pyplot import imshow
from rasterio.session import AWSSession
s3 = boto3.client('s3', aws_access_key_id=AWS_KEY_ID,
aws_secret_access_key=AWS_SECRET)
resources = boto3.resource('s3', aws_access_key_id=AWS_KEY_ID,
aws_secret_access_key=AWS_SECRET)
aws_session = AWSSession(boto3.Session())
cog = 's3://usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/LC08_L2SP_026027_20200827_20200906_02_T1_SR_B2.TIF'
with rio.Env(aws_session):
with rio.open(cog) as src:
profile = src.profile
arr = src.read(1)
imshow(arr)
我收到以下错误:
rasterio.errors.RasterioIOError: '/vsis3/usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/LC08_L2SP_026027_20200827_20200906_02_T1_SR_B2.TIF' does not exist in the file system, and is not recognized as a supported dataset name.
我得到:
An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied
我在 EC2 实例中运行 cloudshell 命令,同样的错误。
我需要在文档中指定我是请求者的权利,这有效:
aws s3 ls s3://usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/ --request-payer requ
ester
使用 boto3 仍然不起作用。
我对运行 boto3 的用户拥有管理员权限。在 CloudShell 中出现与 boto 用户和 root 相同的错误。我以前使用过访问密钥和密钥,它可以很好地从“landsat-pds”存储桶(只有 L8 图像)和“sentinel-s2-l1c”存储桶下载。似乎只有“usgs-landsat”存储桶有问题(https://registry.opendata.aws/usgs-landsat/)
还尝试使用 s3.list_objects 访问 usgs-landsat 存储桶:
landsat = resources.Bucket("usgs-landsat")
all_objects = s3.list_objects(Bucket = 'usgs-landsat')
得到一个类似的错误:
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied
在查看其他解决方案后,一些用户发现:
os.environ["AWS_REQUEST_PAYER"] = "requester"
os.environ["CURL_CA_BUNDLE"] = "/etc/ssl/certs/ca-certificates.crt"
为了解决他们的问题,它对我没有用。