Skip to main content

Moving a Lambda Function to a Shared Log Group Stops Its Logs When the Execution Role Only Covers /aws/lambda

Medium severityAmazon Web Services About 20 minutes to fix

Overview

A Lambda function moved to a shared log group sends nothing when its role only allows /aws/lambda/. Grant the new group, simulate, then move.

At a glance

Symptom
The function's logs stop arriving after its log group is changed, and the new group has no log stream for it.
Likely cause
The execution role decides which log groups the function may write to, and changing LogGroup leaves the role exactly as it was.
Impact
Every invocation between the log group change and the role fix runs without the function's logs reaching CloudWatch Logs.
Verification signal
The fix has worked when the function's own streams appear in the new group within a few minutes of its next invocation.
Safe correction
Grant the role access to the new group first, prove it, and only then move the function or refresh it.
Rollback or recovery
Every step above can be undone on its own, in reverse order.

Pointing a Lambda function at a custom CloudWatch log group with aws lambda update-function-configuration --logging-config LogGroup=shared-app-logs changes where the function sends its logs, but it does not change the execution role. AWS documents that a function needs logs:PutLogEvents to send logs, and that when you set the log group with the AWS CLI, Lambda does not add that permission for you. If the role’s logging statement names only the default group, /aws/lambda/myFunction, the new group stays empty. The fix is to grant the role logs:CreateLogStream and logs:PutLogEvents on the new group’s log streams, prove the grant with aws iam simulate-principal-policy, and only then move the function, or make a trivial configuration update if it has already moved. Do not reach for a grant on every log group to make the problem go away.

Symptom

The function’s logs stop arriving after its log group is changed, and the new group has no log stream for it. Nothing new lands in /aws/lambda/myFunction either, because the function now sends its logs to the group in LoggingConfig.LogGroup. The function’s code has not changed, so its own results give no hint that its logs have gone missing. The problem tends to surface when someone searches for an invocation and finds nothing.

Lambda names streams in a custom group YYYY/MM/DD/<function_name>[<function_version>][<execution_environment_GUID>], so a working function leaves streams that start with the date and its own name. AWS notes that logs can take 5 to 10 minutes to show up after an invocation, so wait that long before reading anything into an empty group.

Why the change looks safe

AWS documents that several functions can share one log group, for example one group for every function in an application. The console makes it look even safer: when you change the log group there, Lambda can add logs:PutLogEvents to the role, under conditions the Lambda guide lists. Anyone used to the console expects the same from the CLI or a pipeline, and does not get it. The role is a separate resource with its own life, in the same way that changing a Lambda execution role does not remove invoke access granted in the function’s resource-based policy: each setting controls only what it controls.

Root cause

The execution role decides which log groups the function may write to, and changing LogGroup leaves the role exactly as it was. The AWS managed policy AWSLambdaBasicExecutionRole grants logs:CreateLogGroup, logs:CreateLogStream and logs:PutLogEvents on "Resource": "*", so a role that relies on it already covers a new group. The Lambda guide also recommends cutting an execution role down to the permissions it needs before production. A role cut down that way may replace the managed policy with an inline statement like this one:

{
  "Effect": "Allow",
  "Action": ["logs:CreateLogStream", "logs:PutLogEvents"],
  "Resource": "arn:aws:logs:eu-west-2:123456789012:log-group:/aws/lambda/myFunction:*"
}

In the Service Authorization Reference, both CreateLogStream and PutLogEvents act on the log-stream resource type, whose ARN is arn:aws:logs:region:account-id:log-group:log_group_name:log-stream:log-stream-name. The statement above matches streams in /aws/lambda/myFunction and nothing else. Streams in shared-app-logs fall outside it, so the role has no permission there.

Impact

Every invocation between the log group change and the role fix runs without the function’s logs reaching CloudWatch Logs. Error output and the START line that shows which version ran are all missing for that window, so record the window as unlogged in any incident or audit trail. The gap lasts until someone notices.

The quick fix that widens the role

Under pressure, the obvious fixes are to attach AWSLambdaBasicExecutionRole, to let the console add the permission, or to write logs:* on *. The managed policy and the logs:* grant both work, and both remove the scoping someone added on purpose: the managed policy’s own "Resource": "*" covers every log group. The console route is no better. AWS states plainly that when the console adds the permission, it gives the function permission to send logs to any CloudWatch Logs log group. Code running as that role, including a compromised dependency, could then write events into other applications’ log groups, the logs you rely on in an incident. Granting one group keeps the role as narrow as it was.

How to confirm it without changing anything

All of these are read-only. Run them with credentials that can read the function and the role, in the function’s Region.

  1. Read the function’s role and logging settings:
    aws lambda get-function-configuration --function-name myFunction --query "{Role:Role,LoggingConfig:LoggingConfig}"

    The trap applies when LogGroup is the custom group and Role is a role you scoped yourself.

  2. Find the role’s policies with aws iam list-role-policies --role-name myFunction-role and aws iam list-attached-role-policies --role-name myFunction-role, then read the inline one that holds the logging statement with aws iam get-role-policy --role-name myFunction-role --policy-name lambda-logs. Look at its Resource.
  3. Ask IAM what the role is allowed to do on the new group:
    aws iam simulate-principal-policy \
      --policy-source-arn arn:aws:iam::123456789012:role/myFunction-role \
      --action-names logs:CreateLogStream logs:PutLogEvents \
      --resource-arns "arn:aws:logs:eu-west-2:123456789012:log-group:shared-app-logs:log-stream:example-stream" \
      --query "EvaluationResults[].[EvalActionName,EvalDecision]"

    implicitDeny for both actions confirms the diagnosis. explicitDeny means another policy denies the write, which this fix will not solve.

  4. Check for the function’s streams in the new group:
    aws logs describe-log-streams --log-group-name shared-app-logs --log-stream-name-prefix "2026/11/22/myFunction"

    An empty list, more than 10 minutes after an invocation, matches the symptom.

Rule out one other cause while you are there: AWS documents that custom log group names must not begin with aws/, and that if they do, Lambda cannot create the group and the function’s logs are not sent.

Correction

Grant the role access to the new group first, prove it, and only then move the function or refresh it. For a function that has not moved yet, that order never leaves it pointing at a group it cannot write to.

  1. Save the current state as your backup: aws lambda get-function-configuration --function-name myFunction > myFunction-config-before.json and aws iam get-role-policy --role-name myFunction-role --policy-name lambda-logs > role-policy-before.json. Precondition: aws logs describe-log-groups --log-group-name-prefix shared-app-logs returns the group. If it does not exist, create it through your normal process, with its retention set, before going on.
  2. Add a second inline policy rather than editing the first, so the existing grant on /aws/lambda/myFunction stays in place. Save this as logs-shared-app-logs.json:
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": ["logs:CreateLogStream", "logs:PutLogEvents"],
          "Resource": "arn:aws:logs:eu-west-2:123456789012:log-group:shared-app-logs:log-stream:*"
        }
      ]
    }

    Then run aws iam put-role-policy --role-name myFunction-role --policy-name logs-shared-app-logs --policy-document file://logs-shared-app-logs.json. It produces no output. Rollback: aws iam delete-role-policy --role-name myFunction-role --policy-name logs-shared-app-logs, which removes only this new policy.

  3. Run the simulation from the diagnosis again. Both actions must now return allowed. Stop here if either does not.
  4. If the function has not moved yet, move it now: aws lambda update-function-configuration --function-name myFunction --logging-config LogGroup=shared-app-logs. If it has already moved, AWS advises a trivial update to the function’s code or configuration after adding permissions, so that running instances with outdated credentials are replaced. A description change is a configuration update that does this: aws lambda update-function-configuration --function-name myFunction --description "Logs to shared-app-logs". Rollback for either: set LogGroup=/aws/lambda/myFunction, or put the description back from myFunction-config-before.json.
  5. Leave the original statement for /aws/lambda/myFunction in place. It is what lets a move back to the default group keep working.

If several functions are moving to shared-app-logs, repeat steps 2 to 4 for each role. Sharing a group does not share a role.

Validation

The fix has worked when the function’s own streams appear in the new group within a few minutes of its next invocation. Run describe-log-streams with the date-and-name prefix again: you should see a stream for myFunction with a recent lastEventTimestamp. Then compare LoggingConfig from get-function-configuration with myFunction-config-before.json: only LogGroup should differ. If you made the description change, read the function’s new invocations in the group, not old ones.

Rollback

Every step above can be undone on its own, in reverse order.

  • Function moved and logs still missing: aws lambda update-function-configuration --function-name myFunction --logging-config LogGroup=/aws/lambda/myFunction, which works because the original statement is still on the role.
  • Description changed: set it back from the value in myFunction-config-before.json.
  • New inline policy: aws iam delete-role-policy --role-name myFunction-role --policy-name logs-shared-app-logs. The original lambda-logs policy is untouched; compare it with role-policy-before.json if in doubt.

Stop it happening on the next function

Treat the log group and the role as one change. In infrastructure code, put the log-stream ARN for the new group in the same change that sets LoggingConfig.LogGroup, so neither can ship without the other. Before any change to a function’s log group, run the same simulate-principal-policy check against the target group and fail the change on anything other than allowed. Keep log group names free of the aws/ prefix. Review who can change Lambda configuration at all: the same access review that catches UpdateFunctionCode slipping past the PassRole check should cover log group changes too.

3

Apply the safer control

Before you change production

Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.

Fix commands and configuration

aws lambda update-function-configuration --logging-config LogGroup=shared-app-logs
logs:PutLogEvents
/aws/lambda/myFunction
4

When to escalate

Validation and rollback are covered in the sections above.

Escalate

Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.

The KBY Brief

Fixed? Get the next one before it hits you: The KBY Brief

Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.

About this page

Credited to

Dates

Published

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

After remediation

Further reading stays below the corrective workflow and is selected by platform, category and shared technical keywords.

Discover more

Connected KBY resources