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.
'bucketname'
and'xxxxxx'
are placeholders for the actual value that you are passing, so I can't tell what's wrong with it, but if you are printing the names of your buckets you should be able to use any in that list. – jdehesa Jan 10 '18 at 12:08