Skip to main content
AWS Lambda 1.3.1Last updated in version 1.3.1

Lambda Alias Module

View Source Release Notes

This module creates an AWS Lambda alias that points to a specific version of a Lambda function. An alias is a named pointer to a Lambda function version, allowing you to invoke a specific version using a stable endpoint without needing to know the underlying version number.

Aliases are useful for:

  • Stable endpoints: Invoke a function via an alias name (e.g., live, staging) rather than a version number.
  • Traffic shifting: Gradually shift traffic between two versions using weighted routing for canary or blue/green deployments.
  • Function URLs and event source mappings: Point triggers at an alias so you can update the underlying version without reconfiguring consumers.

How do you do weighted traffic shifting?

You can use the routing_config variable to split traffic between two versions of a Lambda function. This is useful for canary deployments where you want to gradually shift traffic to a new version:

module "lambda_alias" {
source = "git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/lambda-alias?ref=v1.0.0"

name = "live"
function_name = module.my_lambda_function.function_name
function_version = "2"

routing_config = {
additional_version_weights = {
"3" = 0.1 # Send 10% of traffic to version 3
}
}
}

In this example, 90% of traffic goes to version 2 (the primary version) and 10% goes to version 3. You can adjust the weight from 0.0 to 1.0 as you gain confidence in the new version.

Background info

For more information on AWS Lambda, how it works, and how to configure your functions, check out the lambda module documentation.

Sample Usage

main.tf

# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S LAMBDA-ALIAS MODULE
# ------------------------------------------------------------------------------------------------------

module "lambda_alias" {

source = "git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/lambda-alias?ref=v1.3.1"

# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------

# The Lambda function name or ARN to associate with the alias
function_name = <string>

# Lambda function version for which to create the alias
function_version = <string>

# Name for the alias
name = <string>

# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------

# Description of the alias
description = ""

# Lambda alias routing configuration for weighted traffic shifting. Set
# additional_version_weights to a map of version number to weight (0.0 - 1.0).
routing_config = null

}


Reference

Required

function_namestringrequired

The Lambda function name or ARN to associate with the alias

function_versionstringrequired

Lambda function version for which to create the alias

namestringrequired

Name for the alias

Optional

descriptionstringoptional

Description of the alias

""
routing_configobject(…)optional

Lambda alias routing configuration for weighted traffic shifting. Set additional_version_weights to a map of version number to weight (0.0 - 1.0).

object({
additional_version_weights = map(number)
})
null