I have a bucket previously created in the
us-east-1 region that contains the Lambda code I want to deploy in other regions. When I try a Terraform deploy of that same code in the
us-west-2 region I get the following error:
Error creating Lambda function: InvalidParameterValueException: Error occurred while GetObject. S3 Error Code: PermanentRedirect. S3 Error Message: The bucket is in this region: us-east-1. Please use this region to retry the request
I see no way of specifying the region of the S3 bucket in Terraform’s
Is it possible, using Terraform, to have an S3 bucket in one region provide the Lambda code that can be deployed in other regions?
Lambda functions that specify an S3 bucket for the source must reside in the same region as the S3 bucket. This is because behind the scenes they are pulling the code from S3 on demand as the Lambda needs deploying. Pulling across regions would add large amounts of latency and also now create cross region dependencies.
You’ll need to move the Lambda package into the new region which you could potentially do with cross region replication on the S3 bucket or by simply uploading the Lambda function package into an S3 bucket in the other region manually.