AWS 预签名 url 查询字符串说明
AWS presigned url query string explained
我想了解 PUT
方法如何使用预签名 url.
将文件上传到 s3
我正在使用 boto3
库生成预签名的 url 用于放置调用。生成的 url 如下所示:
https://My_bucket.s3.amazonaws.com/?AWSAccessKeyId=<ACCESS_KEY>&Signature=<Signature>&x-amz-security-token=<SEC_TOKEN>&Expires=<Expires>
为了生成 v4
签名,我需要 KeyId
和 SecretAccessKey
.
如果我们查看上面的 url,我们可以看到 KeyId
与 AWSAccessKeyId
匹配,但没有 SecretAccessKey
。
我使用具有管理权限的帐户生成了预签名 url(它还具有 read/write 对 s3
存储桶的访问权限)。据我了解,任何非特权用户都可以使用 link 中的信息将文件上传到 s3
.
有很多文档,但坦率地说,我非常困惑。
如果有人能解释一下,我将不胜感激
1. 签名如何使用。
2. secret_access_key
在哪里?这是从签名派生的吗?
3. 如何使用已签名 url?
中的 uri 查询参数正确生成 v4
签名
当我尝试使用我生成的签名时,出现错误
The authorization header is malformed; the authorization component
"Credential=SIGNATURE/20191217/ap-south-1/s3/aws4_request" is malformed.
这里的问题是,存储桶的位置与生成预签名 url 的代码位于不同的区域。
以下代码适合我。
import boto3
from botocore.client import Config
s3_client = boto3.client('s3', endpoint_url='http://s3.ap-south-1.amazonaws.com', config=boto3.session.Config(signature_version='s3v4'))
response = None
try:
response = s3_client.generate_presigned_url(
'put_object',
Params={
'Bucket': 'bucket-name-to-presign-south1',
'Key': 'car.jpg'},
ExpiresIn=5000)
print(response)
except Exception as e:
print("In client error exception code")
print(e)
以下参考帮助我找到了正确的方向:
https://javiermunhoz.com/blog/2016/02/01/on-s3-endpoints-regions-signatures-and-boto-3.html
我想了解 PUT
方法如何使用预签名 url.
我正在使用 boto3
库生成预签名的 url 用于放置调用。生成的 url 如下所示:
https://My_bucket.s3.amazonaws.com/?AWSAccessKeyId=<ACCESS_KEY>&Signature=<Signature>&x-amz-security-token=<SEC_TOKEN>&Expires=<Expires>
为了生成 v4
签名,我需要 KeyId
和 SecretAccessKey
.
如果我们查看上面的 url,我们可以看到 KeyId
与 AWSAccessKeyId
匹配,但没有 SecretAccessKey
。
我使用具有管理权限的帐户生成了预签名 url(它还具有 read/write 对 s3
存储桶的访问权限)。据我了解,任何非特权用户都可以使用 link 中的信息将文件上传到 s3
.
有很多文档,但坦率地说,我非常困惑。
如果有人能解释一下,我将不胜感激
1. 签名如何使用。
2. secret_access_key
在哪里?这是从签名派生的吗?
3. 如何使用已签名 url?
v4
签名
当我尝试使用我生成的签名时,出现错误
The authorization header is malformed; the authorization component
"Credential=SIGNATURE/20191217/ap-south-1/s3/aws4_request" is malformed.
这里的问题是,存储桶的位置与生成预签名 url 的代码位于不同的区域。
以下代码适合我。
import boto3
from botocore.client import Config
s3_client = boto3.client('s3', endpoint_url='http://s3.ap-south-1.amazonaws.com', config=boto3.session.Config(signature_version='s3v4'))
response = None
try:
response = s3_client.generate_presigned_url(
'put_object',
Params={
'Bucket': 'bucket-name-to-presign-south1',
'Key': 'car.jpg'},
ExpiresIn=5000)
print(response)
except Exception as e:
print("In client error exception code")
print(e)
以下参考帮助我找到了正确的方向: https://javiermunhoz.com/blog/2016/02/01/on-s3-endpoints-regions-signatures-and-boto-3.html