Giter Club home page Giter Club logo

terraform-aws-lambda's Introduction

Terraform AWS module for AWS Lambda

Introduction

This module creates an AWS lambda and all the related resources. It is a complete re-write of our internal terraform lambda module and all functionality has not yet been tested.

Usage

module "lambda-foo" {
  source = "github.com/comtravo/terraform-aws-lambda"

  ################################################
  #        LAMBDA FUNCTION CONFIGURATION         #
  file_name = "${path.root}/artifacts/foo.zip"
  layers = ["${aws_lambda_layer_version.my_awesome_layer.arn}"]

  function_name = "lambda-foo-${terraform.workspace}"
  handler       = "index.foo"
  memory_size   = 1024

  trigger {
    type          = "sqs"
    sns_topic_arn = "some_sns_arn"
  }

  environment = "${merge(
    local.ct_lambda_commons,
    map(
      "foo", "FOO",
      "bar", "BAR",
      "baz", "BAZ",
      "jazz", "JAZZ",
      "lorem", "LOREM"
    )
  )}"

  # out of band configuration is needed because Terraform treats
  # the cloudwatch_log_subscription block as a computed resource
  # and lookup function doesn't work. Accessing via array style is not possible
  # because the cloudwatch_log_subscription block is an optional block.
  enable_cloudwatch_log_subscription = true

  cloudwatch_log_subscription {
    destination_arn = "${module.lambda-elk-logging.lambda_arn}"
    filter_pattern  = "[timestamp=*Z, request_id=\"*-*\", event]"
  }

  #                                              #
  ################################################

  region = "${var.region}"
  role   = "${aws_iam_role.lambda.arn}"
  vpc_config {
    subnet_ids         = ["${module.main_vpc.private_subnets}"]
    security_group_ids = ["${module.main_vpc.vpc_default_sg}"]
  }
}

Pluggable Triggers

Intro

This module has pluggable triggers. The triggers can be passed by the trigger block.

Example:

  trigger {
    type          = "sqs"
    sns_topic_arn = "some_sns_arn"
  }

All the available triggers can be found in the triggers folder

Adding a new trigger

Triggers are regular Terraform modules but only used by the main module. The only mandatory inputs are enable, lambda_function_arn and type.

Below is an example of API Gateway trigger

variable "enable" {
  default = 0
}

variable "lambda_function_arn" {}

resource "aws_lambda_permission" "allow_apigateway" {
  count         = "${var.enable}"
  statement_id  = "AllowExecutionFromApiGateway"
  action        = "lambda:InvokeFunction"
  function_name = "${var.lambda_function_arn}"
  principal     = "apigateway.amazonaws.com"
}

Authors

Module managed by Comtravo.

License

MIT Licensed. See LICENSE for full details.

terraform-aws-lambda's People

Contributors

puneeth-n avatar rpgeeganage avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.