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.
If you bucket is s3://my-bucket-x/
, then use my-bucket-x
for the bucket name in boto3
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With