Skip to content

Malformed log group name when used with terraform-aws-lambda-function #52

@MReggler

Description

@MReggler

Describe the Bug

When using terraform-aws-lambda-function to create a lambda and associated log group, the resulting log groups can in some cases not match the function name, which results in no logs being sent to the created group.

Expected Behavior

I create a lambda using the terraform-aws-lambda-function module, and the name of this lambda contains an underscore

module "lambda" {
  source  = "cloudposse/lambda-function/aws"
  version = "0.5.3"

  function_name      = "my_function_name"
  ...

  context = module.this.context
}

The resultant log group created by this module should be called /aws/lambda/my_function_name.

Instead the log group created is called /aws/lambda/myfunctionname, as the label for the log group contains a regex_replace_chars rule that does not allow for underscores.

This means the AWS creates its own log group (with default config like no expiration) for the lambda, and the log group created by this module is orphaned.

https://github.com/cloudposse/terraform-aws-cloudwatch-logs/blob/f622326cce042d0e49b2613cc994ab710355ac7f/main.tf#L5C1-L13C2

Steps to Reproduce

Invoke the lambda module with var.function_name set to a value that includes an underscore.

Screenshots

Screenshot 2024-02-20 at 16 32 36

Environment

v0.6.6 -- version of the module used in the lambda module -- IS AFFECTED
v0.6.8 -- current version of the module -- IS AFFECTED

Additional Context

This fix requires a bump to the version of the cloudwatch logs module used in the lambda module (and/or anywhere else in the CloudPosse module/component libraries that support the creation of resources with underscores in their names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🐛 An issue with the system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions