简体   繁体   中英

Cant Connect to nexrad aws s3 bucket using python boto3 module

I am trying to connect to Nexrad aws bucket using python boto3, I have the following issues:
1) Code:

import boto3
s3 = boto3.resource('s3')

my_bucket = s3.Bucket('arn:aws:s3:::unidata-nexrad-level2-chunks')

for objects in my_bucket.objects.all():
    print(objects)

Output:
---------------------------------------------------------------------------
ParamValidationError                      Traceback (most recent call last)
<ipython-input-11-0d42db5d6462> in <module>()
      7 my_bucket = s3.Bucket('arn:aws:s3:::unidata-nexrad-level2-chunks')
      8 
----> 9 for objects in my_bucket.objects.all():
     10     print(objects)

11 frames
/usr/local/lib/python3.6/dist-packages/botocore/handlers.py in validate_bucket_name(params, **kwargs)
    226             'the regex "%s" or be an ARN matching the regex "%s"' % (
    227                 bucket, VALID_BUCKET.pattern, VALID_S3_ARN.pattern))
--> 228         raise ParamValidationError(report=error_msg)
    229 
    230 

ParamValidationError: Parameter validation failed:
Invalid bucket name "arn:aws:s3:::unidata-nexrad-level2-chunks": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:s3:[a-z\-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-]{1,63}$"

I am confused about the aws bucket name to use because this is the name mentioned in the documentation https://registry.opendata.aws/noaa-nexrad/

2) I want to access this bucket and download all objects present in the bucket. Will I require any sort of authentication key although this bucket has public access?

Thanks!

There's another way to do this without using boto:

import nexradaws
conn = nexradaws.NexradAwsInterface()
conn.get_avail_scans('2020', '01', '01', 'KLTX')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM