terraform-aws-modules/terraform-aws-lambda

A bucket for lambda layer always deploy in ec-west-1

shig888 opened this issue · 2 comments

Description

I'm trying to create a lambda function and the layer using this module. I want to deploy those in ap-northeast-1, but only a bucket for the layer deployed in eu-west-1 even though I specified region in aws stanza.

Thus, I'd like to know how to specify the bucket region via this module correctly.

  • I have searched the open/closed issues and my issue is not listed.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

  • Module version [Required]:
  • Terraform version:
Terraform v1.3.6
on darwin_amd64
  • Provider version(s):
+ provider registry.terraform.io/hashicorp/aws v4.45.0
+ provider registry.terraform.io/hashicorp/external v2.2.3
+ provider registry.terraform.io/hashicorp/local v2.2.3
+ provider registry.terraform.io/hashicorp/null v3.2.1
+ provider registry.terraform.io/hashicorp/random v3.4.3

Reproduction Code [Required]

terraform {
  required_version = ">= 0.13.1"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 3.19"
    }
    random = {
      source  = "hashicorp/random"
      version = ">= 2.0"
    }
  }
}

provider "aws" {
  region = "ap-northeast-1"
}

module "lambda_function" {
  source        = "terraform-aws-modules/lambda/aws"
  version       = "4.6.0"
  create_role   = false
  timeout       = 240
  memory_size   = 128
  source_path   = local.lambda_src_path
  function_name = "test-function"
  handler       = "lambda_function.lambda_handler"
  runtime       = "python3.9"
  lambda_role   = aws_iam_role.iam_for_lambda.arn
  layers = [
    module.lambda_layer_s3.lambda_layer_arn,
  ]
}

module "lambda_layer_s3" {
  source = "terraform-aws-modules/lambda/aws"

  create_layer = true

  layer_name          = "lambda-layer-s3"
  description         = "My amazing lambda layer (deployed from S3)"
  compatible_runtimes = ["python3.9"]

  source_path = "../../src"

  store_on_s3 = true
  s3_bucket   = "my-bucket-id-with-lambda-builds"
}

Steps to reproduce the behavior:

terraform apply

Expected behavior

A S3 bucket for a lambda layer should be created in ap-northeast-1.

Actual behavior

As a part of the applying, I got this error. It seems the bucket created by this module is in eu-west-1. That is an issue.

Terminal Output Screenshot(s)

module.lambda_function.aws_cloudwatch_log_group.lambda[0]: Creation complete after 1s [id=/aws/lambda/trade-stats-etl-pipeline]
aws_iam_role.iam_for_lambda: Creation complete after 3s [id=iam_for_lambda_usage]
╷
│ Error: uploading object to S3 bucket (my-bucket-id-with-lambda-builds): BucketRegionError: incorrect region, the bucket is not in 'ap-northeast-1' region at endpoint '', bucket is in 'eu-west-1' region
│       status code: 301, request id: 3QK8NCG573B1A622, host id: mRV2u2DvimoTYhh8AIEJ0gzRLeNRVIPE3e83GzGc1RI92PcsrFJxyzj5b32Jf3M1Vz9966BJNmg=
│ 
│   with module.lambda_layer_s3.aws_s3_object.lambda_package[0],
│   on .terraform/modules/lambda_layer_s3/main.tf line 152, in resource "aws_s3_object" "lambda_package":
│  152: resource "aws_s3_object" "lambda_package" {
│ 
╵

Additional context

I thought this just could create an s3 bucket automatically. But S3 bucket name is unique, so I should have specified a bucket created in my region. That means this is just my misunderstanding. Therefore I close this issue.

I'm going to lock this issue because it has been closed for 30 days . This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.