Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can AWS Lambda access S3 buckets from other regions?

I currently try to use AWS Lambda. The lambda function should load the zip file (> 10 MB) from an S3 Bucket. The S3 bucket is located in eu-central-1 while the lambda function is in lambda:us-east-1.

When I try to save the lambda function, I get:

Error occurred while GetObject. S3 Error Code: AuthorizationHeaderMalformed. S3 Error Message: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-central-1'

Is that really the problem? Is it possible to move the lambda function?

The IAM role which executes the Lambda function has the AmazonS3FullAccess policy.

like image 386
Martin Thoma Avatar asked Dec 14 '22 18:12

Martin Thoma


2 Answers

The lambda function has to be in the same region as the S3 bucket you specify at "S3 link URL*":

enter image description here

like image 65
Martin Thoma Avatar answered Jan 12 '23 14:01

Martin Thoma


You can access an S3 bucket in a different region from Lambda. If you are using Python boto3 library, the following code will help you:

import boto3

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

In fact you can access any resource in a different region from AWS Lambda.

like image 33
krishna_mee2004 Avatar answered Jan 12 '23 14:01

krishna_mee2004