Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am using boto3 in aws lambda to fetch object in S3 located in Frankfurt Region. 

v4 is necessary. otherwise, the 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."

Realized ways to configure signature_version http://boto3.readthedocs.org/en/latest/guide/configuration.html

But since I am using AWS lambda, I do not have access to underlying configuration profiles 

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

Is that possible to configure signature_version within this code? use Session for example. Or is there any workaround on this?

1 Answer

0 votes
by (44.4k points)

Use a custom session and the Config from boto3.session rather than using a default 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')

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Jul 23, 2019 in AWS by yuvraj (19.1k points)
0 votes
1 answer
asked Jul 23, 2019 in AWS by yuvraj (19.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...