lambda-function

Category Compute
Latest Version 0.1.0current

Terraform module for lambda-function on aws

Add to your Terraform configuration
module "lambda_function" {
  source  = "registry.patterneddesigns.ca/patterneddesigns/lambda-function/aws"
  version = "0.1.0"

  # Required inputs
  function_name = "..."
  runtime = "..."
  handler = "..."
  source_path = "..."
}

Overview

The lambda-function module creates AWS Lambda functions with production-ready defaults including:

  • Automatic IAM role creation with least-privilege permissions
  • CloudWatch logging enabled by default
  • X-Ray tracing support
  • Optional VPC configuration for private network access
  • Concurrency controls

Category: Compute Provider: AWS Latest Version: 3.1.0

Quick Start

module "api_handler" {
  source  = "registry.patterneddesigns.ca/patterneddesigns/lambda-function/aws"
  version = "3.1.0"

  function_name = "my-api-handler"
  runtime       = "python3.12"
  handler       = "main.handler"
  source_path   = "./src"
}

Key Features

Automatic IAM Role

The module creates an execution role with permissions for:

  • CloudWatch Logs (write)
  • X-Ray (if tracing enabled)
  • VPC networking (if VPC config provided)

Environment Variables

Pass configuration to your function at runtime:

module "processor" {
  source  = "registry.patterneddesigns.ca/patterneddesigns/lambda-function/aws"
  version = "3.1.0"

  function_name = "event-processor"
  runtime       = "nodejs20.x"
  handler       = "index.handler"
  source_path   = "./dist"

  environment_variables = {
    LOG_LEVEL    = "INFO"
    API_ENDPOINT = "https://api.example.com"
  }
}

VPC Access

Deploy functions inside a VPC for private resource access:

module "private_function" {
  source  = "registry.patterneddesigns.ca/patterneddesigns/lambda-function/aws"
  version = "3.1.0"

  function_name = "db-processor"
  runtime       = "python3.12"
  handler       = "main.handler"
  source_path   = "./src"

  vpc_config = {
    subnet_ids         = ["subnet-abc123", "subnet-def456"]
    security_group_ids = ["sg-123456"]
  }
}

Documentation

Registry

View specification on Registry

Inputs

function_name Required
string

The name of the Lambda function

Example:
function_name = my-resource
runtime Required
string

Lambda runtime identifier

Example:
runtime = python3.9
handler Required
string

Function entrypoint in your code

Example:
handler = example-value
source_path Required
string

Path to the function source code

Example:
source_path = /path/to/resource
number Default: 128

Amount of memory in MB allocated to the function

Example:
memory_size = 128
number Default: 30

Maximum execution time in seconds

Example:
timeout = 30

Reserved concurrency limit for the function. Use -1 for no limit, 0 to disable.

Example:
reserved_concurrent_executions = -1

Environment variables passed to the function

Example:
environment_variables = {}
object({ subnet_ids = list(string) security_group_ids = list(string) })

VPC configuration for private network access

Outputs

function_arn

ARN of the Lambda function

function_name

Name of the Lambda function

qualified_arn

ARN with version qualifier

role_arn

ARN of the function's execution role

invoke_arn

ARN for invoking the function via API Gateway