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:07

    With boto3, this is the code :

    s3_client = boto3.resource('s3', region_name='eu-central-1')
    

    or

    s3_client = boto3.client('s3', region_name='eu-central-1')
    
    0 讨论(0)
  • 2020-11-22 15:08

    With node, try

    var s3 = new AWS.S3( {
        endpoint: 's3-eu-central-1.amazonaws.com',
        signatureVersion: 'v4',
        region: 'eu-central-1'
    } );
    
    0 讨论(0)
  • 2020-11-22 15:09

    Check your AWS S3 Bucket Region and Pass proper Region in Connection Request.

    In My Senario I have set 'APSouth1' for Asia Pacific (Mumbai)

    using (var client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, RegionEndpoint.APSouth1))
    {
        GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
        {
            BucketName = bucketName,
            Key = keyName,
            Expires = DateTime.Now.AddMinutes(50),
        };
        urlString = client.GetPreSignedURL(request1);
    }
    
    0 讨论(0)
  • 2020-11-22 15:11

    You should set signatureVersion: 'v4' in config to use new sign version:

    AWS.config.update({
        signatureVersion: 'v4'
    });
    

    Works for JS sdk.

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

    Similar issue with the PHP SDK, this works:

    $s3Client = S3Client::factory(array('key'=>YOUR_AWS_KEY, 'secret'=>YOUR_AWS_SECRET, 'signature' => 'v4', 'region'=>'eu-central-1'));
    

    The important bit is the signature and the region

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

    I was stuck for 3 days and finally, after reading a ton of blogs and answers I was able to configure Amazon AWS S3 Bucket.

    On the AWS Side

    I am assuming you have already

    1. Created an s3-bucket
    2. Created a user in IAM

    Steps

    1. Configure CORS settings

      you bucket > permissions > CORS configuration

      <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
      <CORSRule>
          <AllowedOrigin>*</AllowedOrigin>
          <AllowedMethod>GET</AllowedMethod>
          <AllowedMethod>POST</AllowedMethod>
          <AllowedMethod>PUT</AllowedMethod>
          <AllowedHeader>*</AllowedHeader>
      </CORSRule>
      </CORSConfiguration>```
      
      
    2. Generate A bucket policy

    your bucket > permissions > bucket policy

    It should be similar to this one

     {
         "Version": "2012-10-17",
         "Id": "Policy1602480700663",
         "Statement": [
             {
                 "Sid": "Stmt1602480694902",
                 "Effect": "Allow",
                 "Principal": "*",
                 "Action": "s3:GetObject",
                 "Resource": "arn:aws:s3:::harshit-portfolio-bucket/*"
             }
         ]
     }
    
    PS: Bucket policy should say `public` after this 
    
    1. Configure Access Control List

    your bucket > permissions > acces control list

    give public access

    PS: Access Control List should say public after this

    1. Unblock public Access

    your bucket > permissions > Block Public Access

    Edit and turn all options Off

    **On a side note if you are working on django add the following lines to you settings.py file of your project **

    #S3 BUCKETS CONFIG
    
    AWS_ACCESS_KEY_ID = '****not to be shared*****'
    AWS_SECRET_ACCESS_KEY = '*****not to be shared******'
    AWS_STORAGE_BUCKET_NAME = 'your-bucket-name'
    
    AWS_S3_FILE_OVERWRITE = False
    AWS_DEFAULT_ACL = None
    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
    
    # look for files first in aws 
    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
    
    # In India these settings work
    AWS_S3_REGION_NAME = "ap-south-1"
    AWS_S3_SIGNATURE_VERSION = "s3v4"
    
    
    0 讨论(0)
提交回复
热议问题