Log group name length: "Minimum length of 1. Maximum length of 512", the allowed characters, and where it fails in Terraform

A CloudWatch Logs log group name is between 1 and 512 characters long and only accepts letters, digits, underscore, hyphen, forward slash, period and number…

2026-11-23

The short answer: a CloudWatch Logs log group name is between 1 and 512 characters long. The [CreateLogGroup reference](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_CreateLogGroup.html) states it like this for the logGroupName parameter: "Length Constraints: Minimum length of 1. Maximum length of 512." and "Pattern: [\.\-_/#A-Za-z0-9]+". A longer name, or one with a character outside that pattern, gets InvalidParameterException from the API (HTTP 400, "A parameter is specified incorrectly."). With Terraform the stop usually comes earlier, in the provider, as "name" cannot be longer than 512 characters.

The number fits in one line. The rest of this note is what is worth keeping next to it: which characters are accepted, what the aws/ prefix rule actually means, where the error shows up in a real stack, and how to ask the account before apply.

The four naming rules

The same page lists them. Quoted as written, since this is what people end up searching for:

The third rule tells you what is left out: spaces, colons, at signs, plus signs, accented letters. None of them is in the pattern. The first one sets the scope of uniqueness: the same name can exist in two Regions or in two accounts, but not twice in the same account and Region. That collision has its own entry in the CreateLogGroup error list, ResourceAlreadyExistsException ("The specified resource already exists."), and it has nothing to do with length.

aws/ and /aws/ are not the same prefix

The fourth rule forbids names starting with aws/, with no leading slash. The groups Lambda creates start with a slash: according to the [Lambda guide](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs-loggroups.html), CloudWatch by default creates a group named /aws/lambda/<function name> the first time the function is invoked. Those are different strings, which is why an aws_cloudwatch_log_group named /aws/lambda/my-function is valid.

Where the rule does show up is with custom log groups for Lambda. That same guide says the name must follow the CloudWatch Logs naming rules and must not begin with aws/, and it spells out the consequence: Lambda will not be able to create the log group, and the function's logs will not be sent to CloudWatch. So what you notice is missing logs.

The literal error: what AWS publishes and what it does not

The API reference lists the CreateLogGroup errors by name: InvalidParameterException, LimitExceededException, OperationAbortedException, ResourceAlreadyExistsException and ServiceUnavailableException. It does not publish the full message text for the too-long case or for the invalid-character case, so I am not going to quote one from memory: what the documentation gives verbatim is the constraint ("Maximum length of 512") and the pattern.

The message that can be quoted word for word is Terraform's, because it lives in the [provider source](https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/logs/validate.go):

"name" cannot be longer than 512 characters: "<the name>"

"name" isn't a valid log group name (alphanumeric characters, underscores,
hyphens, slashes, hash signs and dots are allowed): "<the name>"

"name_prefix" cannot be longer than 483 characters: "<the prefix>"

That validation runs in the provider, before any call to AWS. It uses the pattern ^[0-9A-Za-z_./#-]+$, the same character set as the API. The less known detail is name_prefix: the [resource documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) says it creates a unique name beginning with the given prefix, and the provider caps that prefix at 483 characters, not 512. The final name also carries the suffix Terraform generates (26 characters, per the UniqueIDSuffixLength constant in the [SDK](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/id/id.go)). Both name and name_prefix force a new resource when they change.

Where it bites in practice

With Lambda's automatic group, length is not the problem. A function name is limited to 64 characters ([CreateFunction](https://docs.aws.amazon.com/lambda/latest/api/API_CreateFunction.html): "If you specify only the function name, it is limited to 64 characters in length"), and /aws/lambda/ adds 12: 76 at worst. What does happen with that group is the other error. If the function has already been invoked, the group exists, and declaring it in Terraform afterwards under the same name runs into ResourceAlreadyExistsException. The note on "Never expire" log groups covers why that group appears by itself and what stays behind when the function is deleted.

The 512 limit shows up with generated names: a module that builds the name by joining organization, environment, application, component and an identifier, or that uses another resource's value as the name. And on that same path the pattern is easier to hit than the length. An ARN carries colons, a display name carries spaces, an email carries an at sign; none of that fits [\.\-_/#A-Za-z0-9]+.

There is one case where nothing can be measured beforehand: when the name depends on a value that is only known after apply. In the JSON plan that attribute shows up under after_unknown, and there is no string to count. It is the same boundary described in the note on the emulated apply: an apply against an emulator executes the Create, so it can catch a parameter constraint, but it starts empty and cannot know whether the name already exists in your account.

Checking before apply, read-only

These are two separate questions. Length and characters can be checked against the plan without calling AWS. Whether the name already exists is a question for the account, through describe-log-groups, which is read-only:

#!/usr/bin/env bash
set -euo pipefail
terraform plan -out plan.out -input=false
terraform show -json plan.out \
  | jq -r '.resource_changes[] | select(.type=="aws_cloudwatch_log_group" and (.change.actions|index("create"))) | .change.after.name // empty' \
  | while read -r n; do
      # length and pattern, without calling AWS
      [ "${#n}" -le 512 ] || { echo "$n: ${#n} characters, maximum 512"; exit 1; }
      [[ "$n" =~ ^[0-9A-Za-z_./#-]+$ ]] || { echo "$n: character outside the pattern"; exit 1; }
      # does it already exist in this account and Region? empty output = free
      aws logs describe-log-groups --log-group-name-prefix "$n" \
        --query "logGroups[?logGroupName=='$n'].logGroupName" --output text
    done

Three details from the [describe-log-groups reference](https://docs.aws.amazon.com/cli/latest/reference/logs/describe-log-groups.html). The filter is a prefix match, so /app/api also returns /app/api-worker; that is why the query compares the exact name. The --log-group-name-prefix parameter carries the same constraints as the name (minimum 1, maximum 512, same pattern), so an invalid name fails in the lookup too. And the operation is paginated, with at most 50 per page; the CLI makes as many calls as it needs.

The other limits, in the same place

What tends to come attached to the name question, each with its source:

The quotas come from the [CloudWatch Logs quotas page](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch_limits_cwl.html), which notes that most of them, but not all, are listed in the Service Quotas console. Name length is not a quota: it is a parameter constraint, and there is no increase to request. The same page gives the command to list the default values:

aws service-quotas list-aws-default-service-quotas \
    --query 'Quotas[*].{Adjustable:Adjustable,Name:QuotaName,Value:Value,Code:QuotaCode}' \
    --service-code logs \
    --output table

What Control Cloud does with this

Not much, and it is better to say so. Control Cloud reads the account through the provider's API with a read-only credential and shows the resources it finds and what they cost. It does not validate log group names or check quotas, and today the AWS inventory does not include log groups: the commands above are the tool for that. If you want to see the rest of the account on a map, you can sign in free with your Google account; the Solo plan is free, with a 7-day trial.

Which one did you run into: the 512 characters, a character outside the pattern, or a name that already existed? And where did that name come from: typed by hand, or built by a module?