1

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}$\"

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Can you please take a look at this? stackoverflow.com/questions/64980652/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.