Reputation: 597
I want to upload a file to a subfolder in a Bucket in AWS S3. I am using the code given below.
filename = '/tmp/' + 'image' + '.png'
file_obj = open(filename, 'rb')
s3_upload = s3.put_object( Bucket="aaa/Bbb/cc-cc", Key="filename.png", Body=file_obj)
return
{
'statusCode': 200,
'body': json.dumps("Executed Successfully"
}
The above concept of uploading files to a subfolder of AWS S3 Bucket works fine in Node.js
but when implemented in python
then it gives the following error.
Parameter validation failed:\nInvalid bucket name \"aaa/Bbb/cc-cc\": Bucket name must match the regex \"^[a-zA-Z0-9.\\-_]{1,255}$\" or be an ARN matching the regex \"^arn:(aws).*:s3:[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}$\"
Upvotes: 1
Views: 1463
Reputation: 238189
In your case bucket name is just aaa
, while /Bbb/cc-cc
should be part of the keyname:
s3_upload = s3.put_object( Bucket="aaa", Key="/Bbb/cc-cc/filename.png", Body=file_obj)
Upvotes: 2