The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256

前端 未结 20 1164
既然无缘
既然无缘 2020-11-22 14:19

I get an error AWS::S3::Errors::InvalidRequest The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256. when I try upload fi

相关标签:
20条回答
  • 2020-11-22 15:02

    Code for Flask (boto3)

    Don't forget to import Config. Also If you have your own config class, then change its name.

    from botocore.client import Config
    
    s3 = boto3.client('s3',config=Config(signature_version='s3v4'),region_name=app.config["AWS_REGION"],aws_access_key_id=app.config['AWS_ACCESS_KEY'], aws_secret_access_key=app.config['AWS_SECRET_KEY'])
    s3.upload_fileobj(file,app.config["AWS_BUCKET_NAME"],file.filename)
    url = s3.generate_presigned_url('get_object', Params = {'Bucket':app.config["AWS_BUCKET_NAME"] , 'Key': file.filename}, ExpiresIn = 10000)
    
    0 讨论(0)
  • 2020-11-22 15:02

    Sometime the default version will not update. Add this command

    AWS_S3_SIGNATURE_VERSION = "s3v4"
    

    in settings.py

    0 讨论(0)
  • 2020-11-22 15:05

    For thumbor-aws, that used boto config, i needed to put this to the $AWS_CONFIG_FILE

    [default]
    aws_access_key_id = (your ID)
    aws_secret_access_key = (your secret key)
    s3 =
        signature_version = s3
    

    So anything that used boto directly without changes, this may be useful

    0 讨论(0)
  • 2020-11-22 15:05

    In my case, the request type was wrong. I was using GET(dumb) It must be PUT.

    0 讨论(0)
  • 2020-11-22 15:06

    For people using boto3 (Python SDK) use the below code

    from botocore.client import Config
    
    
    s3 = boto3.resource(
        's3',
        aws_access_key_id='xxxxxx',
        aws_secret_access_key='xxxxxx',
        config=Config(signature_version='s3v4')
    )
    
    0 讨论(0)
  • 2020-11-22 15:06

    I have been using Django, and I had to add these extra config variables to make this work. (in addition to settings mentioned in https://simpleisbetterthancomplex.com/tutorial/2017/08/01/how-to-setup-amazon-s3-in-a-django-project.html).

    AWS_S3_REGION_NAME = "ap-south-1"
    

    Or previous to boto3 version 1.4.4:

    AWS_S3_REGION_NAME = "ap-south-1"
    
    AWS_S3_SIGNATURE_VERSION = "s3v4"
    
    0 讨论(0)
提交回复
热议问题