ruby 您提供的授权机制不受支持。请使用 AWS4-HMAC-SHA256
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26533245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256
提问by Alexey
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 file to S3 bucket in new Frankfurt region. All works properly with US Standardregion.
AWS::S3::Errors::InvalidRequest The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.当我尝试将文件上传到新法兰克福地区的 S3 存储桶时出现错误。所有US Standard区域都可以正常工作。
Script:
脚本:
backup_file = '/media/db-backup_for_dev/2014-10-23_02-00-07/slave_dump.sql.gz'
s3 = AWS::S3.new(
access_key_id: AMAZONS3['access_key_id'],
secret_access_key: AMAZONS3['secret_access_key']
)
s3_bucket = s3.buckets['test-frankfurt']
# Folder and file name
s3_name = "database-backups-last20days/#{File.basename(File.dirname(backup_file))}_#{File.basename(backup_file)}"
file_obj = s3_bucket.objects[s3_name]
file_obj.write(file: backup_file)
aws-sdk (1.56.0)
aws-sdk (1.56.0)
How to fix it?
如何解决?
Thank you.
谢谢你。
回答by Michael - sqlbot
AWS4-HMAC-SHA256, also known as Signature Version 4, ("V4") is one of two authentication schemes supported by S3.
AWS4-HMAC-SHA256,也称为签名版本 4,(“V4”)是 S3 支持的两种身份验证方案之一。
All regions support V4, but US-Standard¹, and many -- but not all -- other regions, also support the other, older scheme, Signature Version 2 ("V2").
所有地区都支持 V4,但美国标准¹,以及许多(但不是全部)其他地区也支持另一个较旧的方案,即签名版本 2(“V2”)。
According to http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html... new S3 regions deployed after January, 2014 will only support V4.
根据http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html... 2014 年 1 月之后部署的新 S3 区域将仅支持 V4。
Since Frankfurt was introduced late in 2014, it does not support V2, which is what this error suggests you are using.
由于法兰克福于 2014 年底推出,它不支持 V2,这就是此错误表明您正在使用的内容。
http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.htmlexplains how to enable V4 in the various SDKs, assuming you are using an SDK that has that capability.
http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html解释了如何在各种 SDK 中启用 V4,假设您使用的是具有该功能的 SDK。
I would speculate that some older versions of the SDKs might not support this option, so if the above doesn't help, you may need a newer release of the SDK you are using.
我推测某些较旧版本的 SDK 可能不支持此选项,因此如果上述方法没有帮助,您可能需要使用较新版本的 SDK。
¹US Standardis the former name for the S3 regional deployment that is based in the us-east-1region. Since the time this answer was originally written,
"Amazon S3 renamed the US Standard Region to the US East (N. Virginia) Region to be consistent with AWS regional naming conventions."For all practical purposes, it's only a change in naming.
¹US Standard是位于该区域的 S3 区域部署的us-east-1旧称。从最初撰写此答案时起,
“Amazon S3 将美国标准区域重命名为美国东部(弗吉尼亚北部)区域,以与 AWS 区域命名约定保持一致。” 出于所有实际目的,这只是命名的更改。
回答by morris4
With node, try
使用节点,尝试
var s3 = new AWS.S3( {
endpoint: 's3-eu-central-1.amazonaws.com',
signatureVersion: 'v4',
region: 'eu-central-1'
} );
回答by Denis Rizun
You should set signatureVersion: 'v4'in configto use new sign version:
你应该设置signatureVersion: 'v4'在config使用新的标志版本:
AWS.config.update({
signatureVersion: 'v4'
});
Works for JSsdk.
适用于JSsdk。
回答by Penkey Suresh
For people using boto3(Python SDK) use the below code
对于使用boto3( Python SDK) 的人,请使用以下代码
from botocore.client import Config
s3 = boto3.resource(
's3',
aws_access_key_id='xxxxxx',
aws_secret_access_key='xxxxxx',
config=Config(signature_version='s3v4')
)
回答by Pascal
Similar issue with the PHP SDK, this works:
与 PHP SDK 类似的问题,这有效:
$s3Client = S3Client::factory(array('key'=>YOUR_AWS_KEY, 'secret'=>YOUR_AWS_SECRET, 'signature' => 'v4', 'region'=>'eu-central-1'));
The important bit is the signatureand the region
最重要的一点是signature和region
回答by SuperNova
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).
我一直在使用 Django,我不得不添加这些额外的配置变量来完成这项工作。(除了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:
或者在 boto3 版本 1.4.4 之前:
AWS_S3_REGION_NAME = "ap-south-1"
AWS_S3_SIGNATURE_VERSION = "s3v4"
回答by Benoit
With boto3, this is the code :
使用 boto3,这是代码:
s3_client = boto3.resource('s3', region_name='eu-central-1')
or
或者
s3_client = boto3.client('s3', region_name='eu-central-1')
回答by GameScripting
In Java I had to set a property
在 Java 中,我必须设置一个属性
System.setProperty(SDKGlobalConfiguration.ENFORCE_S3_SIGV4_SYSTEM_PROPERTY, "true")
and add the region to the s3Client instance.
并将区域添加到 s3Client 实例。
s3Client.setRegion(Region.getRegion(Regions.EU_CENTRAL_1))
回答by higuita
For thumbor-aws, that used boto config, i needed to put this to the $AWS_CONFIG_FILE
对于使用 boto 配置的thumbor-aws,我需要将其放入 $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
所以任何直接使用 boto 而不做更改的东西,这可能很有用
回答by Ian Darke
For Android SDK, setEndpoint solves the problem, although it's been deprecated.
对于 Android SDK, setEndpoint 解决了这个问题,尽管它已被弃用。
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
context, "identityPoolId", Regions.US_EAST_1);
AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
s3.setEndpoint("s3.us-east-2.amazonaws.com");

