问题描述
我正在aws lambda中使用boto3感染位于法兰克福地区的S3中的对象.
I am using boto3 in aws lambda to fecth object in S3 located in Frankfurt Region.
v4是必需的.否则将返回以下错误
v4 is necessary. otherwise following error will return
"errorMessage": "An error occurred (InvalidRequest) when calling
the GetObject operation: The authorization mechanism you have
provided is not supported. Please use AWS4-HMAC-SHA256."
配置签名版本的实际方法 http://boto3.readthedocs.org/en/latest/guide/configuration.html
Realized ways to configure signature_version http://boto3.readthedocs.org/en/latest/guide/configuration.html
但是由于我正在使用AWS lambda,所以我无权访问基础配置配置文件
But since I am using AWS lambda, I do not have access to underlying configuration profiles
我的AWS lambda函数的代码
The code of my AWS lambda function
from __future__ import print_function
import boto3
def lambda_handler (event, context):
input_file_bucket = event["Records"][0]["s3"]["bucket"]["name"]
input_file_key = event["Records"][0]["s3"]["object"]["key"]
input_file_name = input_file_bucket+"/"+input_file_key
s3=boto3.resource("s3")
obj = s3.Object(bucket_name=input_file_bucket, key=input_file_key)
response = obj.get()
return event #echo first key valuesdf
是否可以在此代码中配置signature_version?例如使用会话.还是对此有任何解决方法?
Is that possible to configure signature_version within this code ? use Session for example. Or is there any workaround on this?
推荐答案
而不是使用默认会话,请尝试使用自定义会话和来自boto3.session的Config
Instead of using the default session, try using custom session and Config from boto3.session
import boto3
import boto3.session
session = boto3.session.Session(region_name='eu-central-1')
s3client = session.client('s3', config= boto3.session.Config(signature_version='s3v4'))
s3client.get_object(Bucket='<Bkt-Name>', Key='S3-Object-Key')
这篇关于如何配置与Boto3内联的授权机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!