4

I'm trying to create a lambda alias for my lambda function using terraform. I've been able to successfully create the alias but the created alias is missing the dynamodb as the trigger.

how the event source is set up

resource "aws_lambda_event_source_mapping" "db_stream_trigger" {
    batch_size = 10
    event_source_arn = "${data.terraform_remote_state.testddb.table_stream_arn}"
    enabled = true
    function_name = "${aws_lambda_function.test_lambda.arn}"
    starting_position = "LATEST"
}

how the alias is created

resource "aws_lambda_alias" "test_lambda_alias" {
  count = "${var.create_alias ? 1 : 0}"
  depends_on       = [ "aws_lambda_function.test_lambda" ]
  name             = "test_alias"
  description      = "alias for my test lambda"
  function_name    = "${aws_lambda_function.test_lambda.arn}"
  function_version = "${var.current_running_version}"
  routing_config = {
    additional_version_weights = "${map(
        "${aws_lambda_function.test_lambda.version}", "0.5"
    )}"
  }
}

The lambda works with the dynamodb stream as a trigger The Alias for the lambda is successfully created. The Alias is using the correct version The Alias is using the correct weight The Alias is NOT using the dynamo-db stream as the event source

Hoist
  • 41
  • 3

1 Answers1

0

I had the wrong function_name for the resource "aws_lambda_event_source_mapping". I was providing it the main lambda function's arn as oppose to the alias lambda function's arn. Once i switched it to the alias's arn, I was able to successfully divide the traffic from the stream dependent on the weight!

From aws doc:

Simplify management of event source mappings – Instead of using Amazon Resource Names (ARNs) for Lambda function in event source mappings, you can use an alias ARN. This approach means that you don't need to update your event source mappings when you promote a new version or roll back to a previous version. https://docs.aws.amazon.com/lambda/latest/dg/aliases-intro.html

Hoist
  • 41
  • 3