Skip to content

Terraform module designed to facilitate the creation of AWS Lambda functions

License

Notifications You must be signed in to change notification settings

enter-at/terraform-aws-lambda

Repository files navigation

enter-at

terraform-aws-lambda Build Status Latest Release Semantic Release

Terraform module designed to facilitate the creation of AWS Lambda functions.


It's 100% Open Source and licensed under the APACHE2.

Usage

IMPORTANT: The master branch is used in source just as an example. In your code, do not pin to master because there may be breaking changes between releases. Instead pin to the release tag (e.g. ?ref=tags/x.y.z) of one of our latest releases.

Simple Example

module "lambda" {
  source        = "git::https://github.com/enter-at/terraform-aws-lambda.git?ref=master"
  function_name = "test-service"
  handler       = "service/handler"
  source_dir    = var.source_dir
  runtime       = var.runtime

  rsync_pattern = [
    "--include='*.js'"
  ]
}

Advanced Example

locals {
  service_dir = "account-data"
}

module "lambda" {
  source        = "git::https://github.com/enter-at/terraform-aws-lambda.git?ref=master"
  function_name = "test-service"
  handler       = "${local.service_dir}/handler"
  source_dir    = var.source_dir
  runtime       = var.runtime
  layers        = var.layers
  publish       = true

  provisioned_concurrency_config = {
    qualifier                         = aws_lambda_alias.production.name
    provisioned_concurrent_executions = var.provisioned_concurrent_executions
  }

  rsync_pattern = [
    "--include={lib,domain,${local.service_dir}}/",
    "--include='*.js'"
  ]

  policy = {
    json = data.aws_iam_policy_document.main.json
  }

  environment = {
    variables = {
      SM_SERVICE_CONFIG = var.secrets_manager_secret.arn
    }
  }

  vpc_config = {
    subnet_ids = var.private_subnet_ids

    security_group_ids = [
      var.security_group_id
    ]
  }

  tags = {
    "Team" = "XYZ"
  }
}

resource "aws_lambda_alias" "production" {
  function_name    = module.lambda.function_name
  function_version = module.lambda.function_version
  name             = "production"
}

Inputs

Name Description Type Default Required
cloudwatch_log_subscription_filter (Optional) A list of CloudWatch Logs subscription filter. object null no
dead_letter_config (Optional) Nested block to configure the function's dead letter queue. object null no
description (Optional) Description of what the Lambda function does. string null no
environment (Optional) The Lambda environment's configuration settings. object null no
force_detach_policies (Optional) Specifies to force detaching any policies the role has before destroying it. Defaults to false. bool false no
function_name (Required) A unique name for the Lambda function. string - yes
handler (Required) The function entrypoint in your code. string - yes
layers (Optional) List of Lambda Layer Version ARNs (maximum of 5) to attach to the Lambda function. list(string) null no
memory_size (Optional) Amount of memory in MB the Lambda function can use at runtime. Defaults to 128. number 128 no
module_name (Optional) The location of the handler source code module. Defaults to '.' string . no
policy (Optional) An additional policy to attach to the Lambda function role. object null no
provisioned_concurrency_config (Optional) Lambda Provisioned Concurrency Configuration. object null no
publish (Optional) Whether to publish creation/change as new Lambda function version. Defaults to false. bool false no
reserved_concurrent_executions (Optional) The amount of reserved concurrent executions for this Lambda function. number null no
rsync_pattern (Optional) A list of rsync pattern to include or exclude files and directories. list(string) <list> no
runtime (Required) The identifier of the function's runtime. string - yes
source_dir (Required) The location of the handler source code. string - yes
tags (Optional) A mapping of tags to assign to the object. map(string) null no
timeout (Optional) The amount of time the Lambda function has to run in seconds. Defaults to 3. number 3 no
tracing_config (Optional) A child block with a single argument mode object null no
vpc_config (Optional) Provide this to allow your function to access the VPC. object null no

Outputs

Name Description
arn The Amazon Resource Name (ARN) identifying the Lambda function.
function_name The name identifying the Lambda function.
function_timeout The amount of time the Lambda function can run in seconds.
function_version The latest published version of the Lambda function.
invoke_arn The ARN to be used for invoking the Lambda function
role_arn The ARN of the IAM role created for the Lambda function
role_name The name of the IAM role created for the Lambda function

Share the Love

Like this project? Please give it a ★ on our GitHub!

Related Projects

Check out these related projects.

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

If you are interested in being a contributor and want to get involved in developing this project, we would love to hear from you!

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Contributors

Steffen Leistner