Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a terraform example to deploy Quickwit lambdas #4431

Open
fmassot opened this issue Jan 18, 2024 · 6 comments
Open

Add a terraform example to deploy Quickwit lambdas #4431

fmassot opened this issue Jan 18, 2024 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@fmassot
Copy link
Contributor

fmassot commented Jan 18, 2024

Coming from a redditor: provide terraform examples to deploy Quickwit Lambdas.

@fmassot fmassot added enhancement New feature or request good first issue Good for newcomers labels Jan 18, 2024
@kalil-pelissier
Copy link
Contributor

Hi 👋,
I will be happy to start working on this issue if it's still up to date!

@bjernie
Copy link

bjernie commented May 26, 2024

@kalil-pelissier Do you have any update?

@kalil-pelissier
Copy link
Contributor

Hi, @bjernie didn't start to work on it.
Do you want to work on this issue?

@bjernie
Copy link

bjernie commented May 27, 2024

No, not right now

@hjander
Copy link

hjander commented May 29, 2024

Hi @kalil-pelissier , i would like to try. Any hints or pointers ?

@bjernie
Copy link

bjernie commented May 29, 2024

@hjander I decided to give I at try and it worked beautifully. I am not yet ready to create a PR but this is the terraform code.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">=5.51.1"
    }
  }
}

provider "aws" {
  region = "eu-west-3"
}

locals {
  index_config_key = "index-config.yaml"
  index_config = yamldecode(file("../${local.index_config_key}"))
}

// S3
resource "aws_s3_bucket" "index" {
  bucket        = "quickwit-index-bucket"
  force_destroy = true
}

resource "aws_s3_bucket_policy" "index" {
  bucket = aws_s3_bucket.index.bucket
  policy = data.aws_iam_policy_document.index_policy.json
}

data "aws_iam_policy_document" "index_policy" {
  statement {
    effect  = "Allow"
    actions = ["s3:*"]
    resources = [
      aws_s3_bucket.index.arn,
      "${aws_s3_bucket.index.arn}/*"
    ]
    principals {
      type = "Service"
      identifiers = [
        "lambda.amazonaws.com"
      ]
    }
  }
}

// Upload the index config to the bucket
resource "aws_s3_object" "index_config" {
  bucket = aws_s3_bucket.index.bucket
  key    = local.index_config_key
  content = file("../${local.index_config_key}")
}

// Indexer Lambda
module "indexer_lambda" {
  source             = "terraform-aws-modules/lambda/aws"
  function_name      = "quickwit-indexer"
  source_path        = "cdk.out/indexer/bootstrap"
  handler            = "bootstrap"
  runtime            = "provided.al2023"
  memory_size        = 3008
  timeout            = 900
  attach_policy_json = true
  policy_json        = data.aws_iam_policy_document.indexer_lambda_policy.json
  environment_variables = {
    QW_LAMBDA_INDEX_BUCKET     = aws_s3_bucket.index.bucket
    QW_LAMBDA_METASTORE_BUCKET = aws_s3_bucket.index.bucket
    QW_LAMBDA_INDEX_ID         = local.index_config.index_id
    QW_LAMBDA_INDEX_CONFIG_URI = "s3://${aws_s3_bucket.index.bucket}/${local.index_config_key}"
    RUST_LOG                   = "quickwit=debug"
  }
}

data "aws_iam_policy_document" "indexer_lambda_policy" {
  statement {
    effect = "Allow"
    actions = [
      "s3:*"
    ]
    resources = [
      aws_s3_bucket.index.arn,
      "${aws_s3_bucket.index.arn}/*"
    ]
  }
}

// Searcher Lambda
module "searcher_lambda" {
  source             = "terraform-aws-modules/lambda/aws"
  function_name      = "quickwit-searcher"
  source_path        = "cdk.out/searcher/bootstrap"
  handler            = "bootstrap"
  runtime            = "provided.al2023"
  memory_size        = 3008
  timeout            = 30
  attach_policy_json = true
  policy_json        = data.aws_iam_policy_document.searcher_lambda_policy.json
  environment_variables = {
    QW_LAMBDA_INDEX_BUCKET     = aws_s3_bucket.index.bucket
    QW_LAMBDA_METASTORE_BUCKET = aws_s3_bucket.index.bucket
    QW_LAMBDA_INDEX_ID         = local.index_config.index_id
    RUST_LOG                   = "quickwit=debug"
  }
}

data "aws_iam_policy_document" "searcher_lambda_policy" {
  statement {
    effect = "Allow"
    actions = [
      "s3:*"
    ]
    resources = [
      aws_s3_bucket.index.arn,
      "${aws_s3_bucket.index.arn}/*"
    ]
  }
  statement {
    effect = "Allow"
    actions = [
      "s3:GetObject"
    ]
    resources = ["arn:aws:s3:::quickwit-datasets-public/*"]
  }
  statement {
    effect = "Allow"
    actions = [
      "s3:GetObject"
    ]
    resources = [
      aws_s3_bucket.index.arn,
      "${aws_s3_bucket.index.arn}/*",
    ]
  }
}

This Terraform example is based on the lambda beta 01, which works like as its supposed to.
But trying to use the latest beta 04 makes the searcher lambda throw a "route not found" error, which I haven't managed to find a fix for yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants