Open GBY-1 opened 1 month ago
Thanks for reaching out. Have you reviewed the performance guidelines for S3 here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/optimizing-performance-guidelines.html ? Please let us know what you have tried thus far.
Both the AWS CLI and Boto3 use Botocore, so I would expect to see similar download speeds. Are you using the latest version of Boto3? And what difference in download speed are you seeing?
Please provide a complete code snippet as well as debug logs (with sensitive info redacted) by adding boto3.set_stream_logger('')
to your script for us to investigate this further.
environment: Name: boto3 Version: 1.34.113
my python code are follow as:(aws account is privacy,I dont provide.For example:USERNAME,PASSWORD ) `import boto3 from datetime import datetime from io import BytesIO from botocore.config import Config import logging
bucket_name = 'sentinel-s2-l1c' s3_object_key = 'tiles/49/T/EE/2023/7/4/0/B01.jp2' profix = 'tiles/49/T/EE/2023/7/4/0/'
start_byte = 0 per_byte = 1024 1024 2 filepath = 'F:/gbytemp/test.tif'
boto3.set_stream_logger('') config = Config(connect_timeout=10, read_timeout=30, region_name='eu-central-1') s3 = boto3.resource('s3',aws_access_key_id=USERNAME,aws_secret_access_key=PASSWORD,config=config) bucket = s3.Bucket(bucket_name) object = s3.Object(bucket_name,s3_object_key) starttime = datetime.now() print(starttime) response = object.get(RequestPayer='requester') content = response['Body'] with open(filepath, 'wb') as f: while True: towrite = content.read(per_byte) if not towrite: break f.seek(start_byte) f.write(towrite) start_byte = start_byte + per_byte print(start_byte) `
loggings show:
`2024-06-13 14:32:43,280 botocore.hooks [DEBUG] Event choose-service-name: calling handler <function handle_service_name_alias at 0x000002DB22C86670>
2024-06-13 14:32:43,280 botocore.hooks [DEBUG] Event choose-service-name: calling handler <function handle_service_name_alias at 0x000002DB22C86670>
2024-06-13 14:32:43,282 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function add_generate_presigned_post at 0x000002DB22BF9700>
2024-06-13 14:32:43,282 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function add_generate_presigned_post at 0x000002DB22BF9700>
2024-06-13 14:32:43,283 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function lazy_call.
host:sentinel-s2-l1c.s3.eu-central-1.amazonaws.com x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 x-amz-date:20240613T063243Z x-amz-request-payer:requester
host;x-amz-content-sha256;x-amz-date;x-amz-request-payer e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 2024-06-13 14:32:43,378 botocore.auth [DEBUG] CanonicalRequest: GET /tiles/49/T/EE/2023/7/4/0/B01.jp2
host:sentinel-s2-l1c.s3.eu-central-1.amazonaws.com x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 x-amz-date:20240613T063243Z x-amz-request-payer:requester
host;x-amz-content-sha256;x-amz-date;x-amz-request-payer e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 2024-06-13 14:32:43,379 botocore.auth [DEBUG] StringToSign: AWS4-HMAC-SHA256 20240613T063243Z 20240613/eu-central-1/s3/aws4_request ce58c486031b91a9636171b213473dd40565e1f1f5235a0043a179ac300fb093 2024-06-13 14:32:43,379 botocore.auth [DEBUG] StringToSign: AWS4-HMAC-SHA256 20240613T063243Z 20240613/eu-central-1/s3/aws4_request ce58c486031b91a9636171b213473dd40565e1f1f5235a0043a179ac300fb093 2024-06-13 14:32:43,380 botocore.auth [DEBUG] Signature: ca5d9b8d9e58373e646e7b641b075678be0d9b808715f1ed1732d6595fda44ca 2024-06-13 14:32:43,380 botocore.auth [DEBUG] Signature: ca5d9b8d9e58373e646e7b641b075678be0d9b808715f1ed1732d6595fda44ca 2024-06-13 14:32:43,381 botocore.hooks [DEBUG] Event request-created.s3.GetObject: calling handler <function add_retry_headers at 0x000002DB22CA6C10> 2024-06-13 14:32:43,381 botocore.hooks [DEBUG] Event request-created.s3.GetObject: calling handler <function add_retry_headers at 0x000002DB22CA6C10> 2024-06-13 14:32:43,382 botocore.endpoint [DEBUG] Sending http request: <AWSPreparedRequest stream_output=True, method=GET, url=https://sentinel-s2-l1c.s3.eu-central-1.amazonaws.com/tiles/49/T/EE/2023/7/4/0/B01.jp2, headers={'x-amz-request-payer': b'requester', 'User-Agent': b'Boto3/1.34.113 md/Botocore#1.34.113 ua/2.0 os/windows#10 md/arch#amd64 lang/python#3.9.16 md/pyimpl#CPython cfg/retry-mode#legacy Botocore/1.34.113 Resource', 'X-Amz-Date': b'20240613T063243Z', 'X-Amz-Content-SHA256': b'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': b'AWS4-HMAC-SHA256 Credential=USERNAME/20240613/eu-central-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-request-payer, Signature=ca5d9b8d9e58373e646e7b641b075678be0d9b808715f1ed1732d6595fda44ca', 'amz-sdk-invocation-id': b'95592dc5-4bec-417d-b5ae-d3c726a7ec87', 'amz-sdk-request': b'attempt=1'}> 2024-06-13 14:32:43,382 botocore.endpoint [DEBUG] Sending http request: <AWSPreparedRequest stream_output=True, method=GET, url=https://sentinel-s2-l1c.s3.eu-central-1.amazonaws.com/tiles/49/T/EE/2023/7/4/0/B01.jp2, headers={'x-amz-request-payer': b'requester', 'User-Agent': b'Boto3/1.34.113 md/Botocore#1.34.113 ua/2.0 os/windows#10 md/arch#amd64 lang/python#3.9.16 md/pyimpl#CPython cfg/retry-mode#legacy Botocore/1.34.113 Resource', 'X-Amz-Date': b'20240613T063243Z', 'X-Amz-Content-SHA256': b'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': b'AWS4-HMAC-SHA256 Credential=USERNAME/20240613/eu-central-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-request-payer, Signature=ca5d9b8d9e58373e646e7b641b075678be0d9b808715f1ed1732d6595fda44ca', 'amz-sdk-invocation-id': b'95592dc5-4bec-417d-b5ae-d3c726a7ec87', 'amz-sdk-request': b'attempt=1'}> 2024-06-13 14:32:43,383 botocore.httpsession [DEBUG] Certificate path: D:\ProgramData\Anaconda3\envs\webserver\lib\site-packages\certifi\cacert.pem 2024-06-13 14:32:43,383 botocore.httpsession [DEBUG] Certificate path: D:\ProgramData\Anaconda3\envs\webserver\lib\site-packages\certifi\cacert.pem 2024-06-13 14:32:43,385 urllib3.connectionpool [DEBUG] Starting new HTTPS connection (1): sentinel-s2-l1c.s3.eu-central-1.amazonaws.com:443 2024-06-13 14:32:43,385 urllib3.connectionpool [DEBUG] Starting new HTTPS connection (1): sentinel-s2-l1c.s3.eu-central-1.amazonaws.com:443 2024-06-13 14:32:43.358342 2024-06-13 14:32:44,489 urllib3.connectionpool [DEBUG] https://sentinel-s2-l1c.s3.eu-central-1.amazonaws.com:443 "GET /tiles/49/T/EE/2023/7/4/0/B01.jp2 HTTP/1.1" 200 3064426 2024-06-13 14:32:44,489 urllib3.connectionpool [DEBUG] https://sentinel-s2-l1c.s3.eu-central-1.amazonaws.com:443 "GET /tiles/49/T/EE/2023/7/4/0/B01.jp2 HTTP/1.1" 200 3064426 2024-06-13 14:32:44,491 botocore.parsers [DEBUG] Response headers: {'x-amz-id-2': 'eRfOUxPiFiU7Lt0/OSzrNumMSmiBjA/3yXvEzBif4lM9KALMpQrutOURlKokUYBNn8HOF5rT8pQ=', 'x-amz-request-id': 'Q4WDPDZV5EYK73KJ', 'Date': 'Thu, 13 Jun 2024 06:32:46 GMT', 'x-amz-request-charged': 'requester', 'Last-Modified': 'Tue, 04 Jul 2023 08:52:14 GMT', 'ETag': '"6ded918684fdb9895259d1e7bb565b3e"', 'x-amz-storage-class': 'INTELLIGENT_TIERING', 'x-amz-server-side-encryption': 'AES256', 'Accept-Ranges': 'bytes', 'Content-Type': 'application/octet-stream', 'Server': 'AmazonS3', 'Content-Length': '3064426'} 2024-06-13 14:32:44,491 botocore.parsers [DEBUG] Response headers: {'x-amz-id-2': 'eRfOUxPiFiU7Lt0/OSzrNumMSmiBjA/3yXvEzBif4lM9KALMpQrutOURlKokUYBNn8HOF5rT8pQ=', 'x-amz-request-id': 'Q4WDPDZV5EYK73KJ', 'Date': 'Thu, 13 Jun 2024 06:32:46 GMT', 'x-amz-request-charged': 'requester', 'Last-Modified': 'Tue, 04 Jul 2023 08:52:14 GMT', 'ETag': '"6ded918684fdb9895259d1e7bb565b3e"', 'x-amz-storage-class': 'INTELLIGENT_TIERING', 'x-amz-server-side-encryption': 'AES256', 'Accept-Ranges': 'bytes', 'Content-Type': 'application/octet-stream', 'Server': 'AmazonS3', 'Content-Length': '3064426'} 2024-06-13 14:32:44,492 botocore.parsers [DEBUG] Response body: <botocore.response.StreamingBody object at 0x000002DB234A3A00> 2024-06-13 14:32:44,492 botocore.parsers [DEBUG] Response body: <botocore.response.StreamingBody object at 0x000002DB234A3A00> 2024-06-13 14:32:44,493 botocore.hooks [DEBUG] Event needs-retry.s3.GetObject: calling handler <botocore.retryhandler.RetryHandler object at 0x000002DB238629D0> 2024-06-13 14:32:44,493 botocore.hooks [DEBUG] Event needs-retry.s3.GetObject: calling handler <botocore.retryhandler.RetryHandler object at 0x000002DB238629D0> 2024-06-13 14:32:44,494 botocore.retryhandler [DEBUG] No retry needed. 2024-06-13 14:32:44,494 botocore.retryhandler [DEBUG] No retry needed. 2024-06-13 14:32:44,494 botocore.hooks [DEBUG] Event needs-retry.s3.GetObject: calling handler <bound method S3RegionRedirectorv2.redirect_from_error of <botocore.utils.S3RegionRedirectorv2 object at 0x000002DB23862910>> 2024-06-13 14:32:44,494 botocore.hooks [DEBUG] Event needs-retry.s3.GetObject: calling handler <bound method S3RegionRedirectorv2.redirect_from_error of <botocore.utils.S3RegionRedirectorv2 object at 0x000002DB23862910>>`
aws-cli:
aws s3 ls s3://sentinel-s2-l1c/tiles/49/T/EE/2023/7/4/0/ --request-payer
this is a folder,aws-cli down this folder is faster,above boto3 python code down a file in the one of this folder(B01.jpg).
C:\Users\admin>aws s3 cp s3://sentinel-s2-l1c/tiles/49/T/EE/2023/7/4/0 F:\gbytemp --recursive --request-payer
Have you tried using download_file
documented here? You could also try using multi-processing as documented here. What kind of time differences are you seeing? If you can provide a sample file we can investigate further and try testing on our end.
Describe the bug
I use get object donw sentinel data from 'Bucket=sentinel-2-l1c' and 'Bucket=landsat-c2l1'. sentinel-2-l1c down is very slow,but i use aws cli dont this issue.please help me to address this issue
Expected Behavior
promote down speed
Current Behavior
down speed very slow
Reproduction Steps
file_size = int(s3.head_object(Bucket=bucket_name, Key=key, RequestPayer='requester')['ContentLength']) - 1 with open(filepath, 'wb') as f: while True: try: if down_trycount > 2: break
使用range参数获取要下载的字节范围
f.close()
Possible Solution
No response
Additional Information/Context
No response
SDK version used
boto3
Environment details (OS name and version, etc.)
boto3 python3