Lambda functions share an execution role

Separate Lambda execution roles where functions have different permission requirements.

Description

Compare the actions and resources each Lambda function needs. Functions doing the same work within one trust boundary can share a role. Separate their execution roles when access needs or trust boundaries differ.

Potential impact

Granting more access to a shared role can give every function that uses it unnecessary access to data or operations.

Remediation

Configure each role to trust Lambda and review its effective permissions, including shared policies. Test the function, log delivery and required service calls after changing roles.

Examples

Both functions return a fixed response. Supply existing role ARNs and the permissions your production code needs.

Before

yaml
Resources:
  Primer01:
    Type: AWS::Lambda::Function
    Properties:
      Runtime: nodejs22.x
      Role: arn:aws:iam::123456789012:role/lambda-role
      Handler: index.handler
      Code:
        ZipFile: |
          exports.handler = async () => ({ statusCode: 200, body: "ok" });

  Primer02:
    Type: AWS::Lambda::Function
    Properties:
      Runtime: nodejs22.x
      Role: arn:aws:iam::123456789012:role/lambda-role
      Handler: index.handler
      Code:
        ZipFile: |
          exports.handler = async () => ({ statusCode: 200, body: "ok" });

After

yaml
Resources:
  Primer01:
    Type: AWS::Lambda::Function
    Properties:
      Runtime: nodejs22.x
      Role: arn:aws:iam::123456789012:role/lambda-role-primer01
      Handler: index.handler
      Code:
        ZipFile: |
          exports.handler = async () => ({ statusCode: 200, body: "ok" });

  Primer02:
    Type: AWS::Lambda::Function
    Properties:
      Runtime: nodejs22.x
      Role: arn:aws:iam::123456789012:role/lambda-role-primer02
      Handler: index.handler
      Code:
        ZipFile: |
          exports.handler = async () => ({ statusCode: 200, body: "ok" });

The second example assigns different roles to Primer01 and Primer02. Their policies determine what each function can access.

References