Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to know the sample bucket name in boto3

Im new for AWS and im using boto3 for uploading files to s3. But im bit confused in configuring boto3 connection. Below is the code.

import boto3
s3 = boto3.resource(
    's3',
    aws_access_key_id='access_key',
    aws_secret_access_key='secret_key'
)

data = open('test.txt', 'rb')
s3.Bucket('bucketname').put_object(Key='test.txt', Body=data)

I tried to print the bucket names using below code and it worked well.

for bucket in s3.buckets.all():
    print(bucket.name)

But if i give the bucketname in s3.Bucket('xxxxxx').put_object(Key='test.txt', Body=data)

im getting error as:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid bucket name "xxxxxx": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$"

I need help on this.

like image 990
SBN AB Avatar asked Jan 10 '18 12:01

SBN AB


1 Answers

If you bucket is s3://my-bucket-x/, then use my-bucket-x for the bucket name in boto3.

like image 148
imriss Avatar answered Sep 28 '22 19:09

imriss