transcend-io / terraform-aws-lambda-at-edge

Terraform module for making a Lambda@Edge function in terraform
MIT License
27 stars 35 forks source link

Provide usage example? #23

Open xtrinch opened 2 years ago

xtrinch commented 2 years ago

It would be very helpful to have an examples/ folder with a sample lambda usage example

TheVexy commented 2 years ago

Here's a small example (don't mind the providers argument, that's just bcs in my case most of resources needs to go to eu-central regions) : You use lambda_code_source_dir to point at the folder that contains your lambda code, In my case I overwrite file_globs to also upload redirects.json file if you want to quickly create an cloudwatch kms key there is a module for that as well : https://registry.terraform.io/modules/dod-iac/cloudwatch-kms-key/aws/latest

 module "lambda-at-edge" {
   providers = {
    aws = aws.NVirginia
  }
  source  = "transcend-io/lambda-at-edge/aws"
  version = "0.5.0"
  cloudwatch_log_groups_kms_arn = module.cloudwatch-kms-key.aws_kms_key_arn
  name = "origin-request-lambda-edge"
  description = "Used by cloudfront distribution"
  runtime = "nodejs16.x"
  lambda_code_source_dir = "./lambda/origin-request"
  file_globs = ["app.js", "redirects.json"]
  handler = "app.handler"
  s3_artifact_bucket = var.s3_bucket_lambda_code_name
  local_file_dir = "./artifacts"
}