@interlace/serverless
IAM Roles Per Function

Configuration Reference

Every config key for @interlace/serverless-iam-roles-per-function.

Global

Set under custom.interlaceIamRolesPerFunction in serverless.yml (or serverless.ts). The plugin also reads custom.serverless-iam-roles-per-function as a backwards-compat alias for the community plugin's key.

serverless.yml
custom:
  interlaceIamRolesPerFunction:
    defaultInherit: false
    suppressGlobalRole: true
    requirePerFunctionRoles: true
    statementTemplates:
      data-read:
        - Effect: Allow
          Action: ['dynamodb:GetItem', 'dynamodb:Query']
          Resource: '*'

Properties

KeyTypeDefaultDescription
defaultInheritbooleanfalseIf true, every function with iamRoleStatements also includes provider.iam.role.statements. Per-function override via iamRoleStatementsInherit.
iamGlobalPermissionsBoundarystring | Fn::Sub | Fn::ImportValuePermissions boundary applied to the global role and any per-function role that doesn't set its own.
suppressGlobalRolebooleanfalseRemove the broad IamRoleLambdaExecution role from the template. Only safe when every function has its own role — combine with requirePerFunctionRoles: true.
requirePerFunctionRolesbooleanfalseFail the deploy if any function lacks iamRoleStatements. Set iamRoleStatements: [] on intentionally-empty functions.
statementTemplatesRecord<string, IamStatement[]>{}Named base policies referenced by iamRoleStatementsTemplate.

Per-function

Under functions.<name> in serverless.yml:

KeyTypeDescription
iamRoleStatementsIamStatement[]Per-function policy statements. Triggers per-function role creation. Mutually exclusive with role.
iamRoleStatementsInheritbooleanOverride defaultInherit for this function.
iamRoleStatementsNamestringCustom role name (max 64 chars; stripped of Lambda suffix if needed).
iamRoleStatementsTemplatestringName of a template defined under custom.…statementTemplates.
iamPermissionsBoundarystring | Fn::Sub | Fn::ImportValuePermissions boundary for this function's role only.
iamManagedPoliciesstring[]Managed-policy ARNs to attach. AWS-managed VPC policy is auto-attached for VPC-enabled functions.

Auto-permissions

When iamRoleStatements is set on a function, the plugin scans the function's events: block and adds the right permissions automatically:

EventActions granted
events: [sqs: ...]sqs:ReceiveMessage, sqs:DeleteMessage, sqs:GetQueueAttributes
events: [stream: ...] (DynamoDB)dynamodb:GetRecords, GetShardIterator, DescribeStream, ListStreams
events: [stream: ...] (Kinesis)kinesis:GetRecords, GetShardIterator, DescribeStream, ListStreams
onError: arn:aws:sns:...sns:Publish
events: [eventBridge: {eventBus: ...}]events:PutEvents (community plugin: not granted)
events: [s3: ...]s3:GetObject for arn:aws:s3:::<bucket>/* (community plugin: not granted)

The function's own CloudWatch log group statement is always granted (scoped to the function's log group, not *).

See also

On this page