When I try to upload images to a bucket, it throw an error "Invalid bucket name "thum.images ": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$""
.
I think there is nothing wrong with a bucket name.
This is my code to upload image:
def upload_thumbnail_image(image_key, thumbnail_image):
thumbnail_image_bucket = os.environ['thumbnail_bucket']
thumbnail_image = #image path
image_key = EFE3-27C8-EEB3-4987/3612d0bc-bdfd-49de-82ee-3e66cbb06807.jpg
try:
new_object = client.upload_file(thumbnail_image, thumbnail_image_bucket, image_key)
return new_object
except Exception as Exc:
set_log(Exc.args[0],True)
The "Invalid bucket name "thum.images ": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$""
error means just what it says: the bucket name must contain some typo or is just wrong as it should meet the following pattern:
^
- start of string[a-zA-Z0-9.\-_]{1,255}
- 1 to 255 ASCII letters, digits, dots, -
or _
chars$
- end of string.You may test your bucket names online here.
There can be no whitespaces in the bucket name.
I often get this error because an extra slash gets into the bucket name after I copy/paste the bucket name from the S3 Web page, like aws s3 sync s3:///my-bucket/folder folder
, where instead of the triple backslashes there must be just two.