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 aws_lambda_function
resource.
Is it possible, using Terraform, to have an S3 bucket in one region provide the Lambda code that can be deployed in other regions?
S3 event can't trigger a lambda in a different region. What you can do is for example: Send the S3 event to SNS topic or SQS queue and trigger lambda in your target region from that message. Trigger Lambda in the same region from the S3 event and trigger your target region Lambda from the first Lambda.
Can I use lambda across regions? AWS Lambda is a regional service. A single Lambda function in a single region can make API calls to AWS services in other regions, but they're remote, of course, so any data transferred between that Lambda function and the destination services or vice-versa takes longer and costs more.
To give your Lambda function access to an Amazon S3 bucket in the same AWS account, do the following: 1. Create an AWS Identity and Access Management (IAM) role for the Lambda function that also grants access to the S3 bucket. 2.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With