Skip to content

Request help to resolve a botocore.exception due to Invalid bucket name

0

I've spun up an EC2 instance with AWS Linux and python3. I have an S3 bucket "arn:aws:s3:::funrepbucket/bespoke_names/" with sample files but when I run simple download code I am getting:

botocore.exceptions.ParamValidationError: Parameter validation failed: Invalid bucket name "arn:aws:s3:::funrepbucket/bespoke_names/": Bucket name must match the regex "^[a-zA-Z0-9.-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).:(s3|s3-object-lambda):[a-z-0-9]:[0-9]{12}:accesspoint[/:][a-zA-Z0-9-.]{1,63}$|^arn:(aws).*:s3-outposts:[a-z-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9-]{1,63}$"

Please advise. thank you, -Larry

asked a year ago661 views

3 Answers
1

I got confused with the ARN pattern messages coming from the boto exception and mentions of the bucket_uri in the boto3 documentation. It turns out the bucket_uri just needs to be the bucket name, i.e., "funrepbucket"

answered a year ago

  • really hard to find that issue. The complete s3-adressing and global uniqueness is a pain.

0

Hello Larry,

I understand you're encountering an issue with a botocore.exception due to an invalid bucket name. Let me help you resolve this.

The error you're seeing is because you're using the full ARN (Amazon Resource Name) of the S3 object path as the bucket name, which is not the correct format for specifying a bucket in boto3 operations.

When working with S3 in boto3, you need to separate the bucket name from the object key (path). In your case:

  • The bucket name is "funrepbucket"
  • The object key (path) is "bespoke_names/"

To fix this issue, you should modify your code to use just the bucket name "funrepbucket" as the bucket parameter, and then use "bespoke_names/" as the prefix or key in your S3 operations.

For example, if you're trying to download a file, your code might look something like this:

import boto3

s3 = boto3.client('s3')

bucket_name = 'funrepbucket'
object_key = 'bespoke_names/your_file_name.txt'

s3.download_file(bucket_name, object_key, 'local_file_name.txt')

Remember, S3 bucket names must follow certain rules:

  • They can contain lowercase letters, numbers, periods, and hyphens.
  • They must be between 3 and 63 characters long.
  • They can't be formatted as an IP address.
  • They must start with a lowercase letter or number.

By separating the bucket name from the object key and using the correct format, you should be able to resolve the ParamValidationError you're encountering. If you continue to have issues, double-check that your IAM permissions are set correctly to access the S3 bucket and its contents.
Sources
General purpose bucket naming rules - Amazon Simple Storage Service
Resolve the Amazon S3 “IllegalLocationConstraintException” bucket error | AWS re:Post

answered a year ago

EXPERT

reviewed a year ago

  • ok I changed my python bucket name reference to "arn:aws:s3:::funrepbucket" but boto still complains:

    botocore.exceptions.ParamValidationError: Parameter validation failed: Invalid bucket name "arn:aws:s3:::funrepbucket": Bucket name must match the regex "^[a-zA-Z0-9.-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).:(s3|s3-object-lambda):[a-z-0-9]:[0-9]{12}:accesspoint[/:][a-zA-Z0-9-.]{1,63}$|^arn:(aws).*:s3-outposts:[a-z-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9-]{1,63}$"

0

Hello.

Could you please share the code you've created that is causing the problem?
As stated in the automatic response from re:Post Agent, "arn:aws:s3:::funrepbucket" is the ARN, so I think the only thing you need to specify as the bucket name is "funrepbucket".

EXPERT

answered a year ago

  • Following code stored in the py file, executed by:

    $ python test_s3_download.py -v larrys

    import boto3 import argparse

    def main(args): if args.verbose: print('Verbose mode enabled.')

    bucket_uri = 'arn:aws:s3:::funrepbucket'
    attfilename = f"bespoke_names/{args.name}_attributes.csv"
    bespoke_names_filename = f"bespoke_names/{args.name}_names.csv"
    
    if args.verbose:
        print(f"attfilename is {attfilename}")
    
    s3 = boto3.client('s3')
    
    response = s3.list_buckets()
    if args.verbose:
        print('Existing buckets:')
        for bucket in response['Buckets']:
            print(f'  {bucket["Name"]}')
    
    s3.download_file(bucket_uri, attfilename, 'attributes.csv')
    s3.download_file(bucket_uri, bespoke_names_filename, 'names.csv')
    

    if name == 'main': parser = argparse.ArgumentParser(description='Generate report of positions') parser.add_argument('-v', '--verbose', action='store_true', help='Enable verbose output') parser.add_argument('name', help='Indicate name of run ...will be the prefix of related files') args = parser.parse_args() main(args) ###############################

    Output follows

    Verbose mode enabled. attfilename is bespoke_names/larrys_attributes.csv Existing buckets: funrepbucket Traceback (most recent call last): File "/home/ec2-user/test_s3_download.py", line 35, in <module> main(args) File "/home/ec2-user/test_s3_download.py", line 24, in main s3.download_file(buck

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.