Upload image to S3 python


I am trying to upload an image to S3 through Python. My code looks like this:

I am getting this error message:

This code is based on the tutorial from this website: http://stackabuse.com/example-upload-a-file-to-aws-s3/

I have tried k.set_contents_from_file as well as k.set_contents_from_filename, but both don’t seem to work for me.

The error says something about using AWS4-HMAC-SHA256, but I am not sure how to do that. Is there another way to solve this problem besides using AWS4-HMAC-SHA256? If anyone can help me out, I would really appreciate it.

Thank you!


Just use:

Try to avoid putting your credentials in the code. Instead:

  • If you are running the code from an Amazon EC2 instance, simply assign an IAM Role to the instance with appropriate permissions. The credentials will automatically be used.
  • If you are running the code on your own computer, use the AWS Command-Line Interface (CLI) aws configure command to store your credentials in a file, which will be automatically used by your code.

Leave a Reply