Review IAM role separation for Serverless Framework functions

A shared role can grant functions permissions needed only by other functions

Description

Give functions with different permission needs separate IAM execution roles.

Potential impact

A function using a shared role can access resources that only another function needs.

Remediation

Assign a dedicated role to the function or configure per-function IAM permissions. Limit the role’s policy to the actions and resources that function uses.

Examples

For hello, supply the ARN of a role that Lambda can assume.

Before

yaml
service: service
frameworkVersion: "4"
provider:
  name: aws
  runtime: nodejs22.x

functions:
  hello:
    handler: handler.hello

After

yaml
service: service
frameworkVersion: "4"
provider:
  name: aws
  runtime: nodejs22.x

functions:
  hello:
    handler: handler.hello
    role: arn:aws:iam::123456789012:role/hello-function-role

References