Skip to content
Least Privilege Principle

Least privilege for AWS Lambda starts with a narrow execution role and a scoped resource policy

AWS Lambda has two permission paths: the execution role a function uses and the resource-based policy that lets others invoke it. AWS documentation read on 16 Nov 2026 supports full JSON resource policies with condition keys. This guide covers both paths, an invoke grant for S3, and how to trim a role.

Open the calculator ยท All services

Lambda has an execution role and a resource-based policy

AWS documentation describes two categories of permissions: what a function needs to call other AWS resources, and what other entities need to reach the function. The first is defined in the execution role, which every function must have. At a minimum the role needs CloudWatch Logs access, which the AWSLambdaBasicExecutionRole managed policy provides.

The second is set with identity-based policies or resource-based policies. AWS says that when a user calls a function Lambda considers both policy types, and that when an AWS service such as S3 calls a function Lambda considers only the resource-based policy. Attribute-based access control with tags is also supported.

The identities that call this service (people, services, workloads, third parties) are covered in the AWS service identities guide and the workload identities guide.

Development-time breadth and manual role assumption are the habits to avoid

  • Leaving the permissions from the development phase in place. AWS says you may grant more than required at first and should adjust the policy before publishing to production.
  • Starting from an AWS managed policy and never narrowing it. AWS recommends managed policies as a starting point for writing more restrictive ones; one example is AWSLambdaDynamoDBExecutionRole, which a function that reads a DynamoDB stream may use.
  • Calling sts:AssumeRole in function code to assume the execution role. AWS says to avoid it, because Lambda assumes the role automatically on invocation.
  • Using AddPermission statements when you need more control. AWS says individual permissions support only aws:SourceArn, aws:SourceAccount and aws:PrincipalOrgID and recommends full JSON policies.

An invoke grant for S3 names the account and denies one bucket

AWS publishes a resource-based policy that lets every S3 bucket in one account invoke a function except one bucket that is explicitly denied. Setting it needs lambda:PutResourcePolicy, lambda:AddPermission and lambda:RemovePermission.

EffectPrincipalActionCondition
AllowService: s3.amazonaws.comlambda:InvokeFunction on the function ARNStringEquals aws:SourceAccount is the account ID
DenyService: s3.amazonaws.comlambda:InvokeFunction on the function and its versionsArnLike aws:SourceArn is arn:aws:s3:::amzn-s3-demo-bucket

Full JSON policies add explicit denies and organization conditions

AWS documentation says full JSON resource policies, up to 20 KB, can hold multiple principals, explicit Deny statements and the complete range of IAM global condition keys. It lists aws:PrincipalOrgID and aws:PrincipalOrgPaths as ways to restrict access to your organization without listing each account.

AWS warns that put-resource-policy replaces any existing policy. Read the current one with get-resource-policy and pass its RevisionId so an older revision is not applied.

Generate a trimmed role from CloudTrail activity

AWS says IAM Access Analyzer reviews CloudTrail logs over a date range you choose and generates a policy template with only the permissions the function used. The policy generation page allows up to 90 days. You turn the template into a managed policy and attach it to the role.

The same page says generated policies leave out action-level activity for data events. Check the output against what the function does at runtime before replacing the role policy.

Sources

  1. Managing permissions in AWS Lambda, read 16 Nov 2026
  2. Lambda execution role, read 16 Nov 2026
  3. Resource-based policies in Lambda, read 16 Nov 2026
  4. IAM Access Analyzer policy generation, read 16 Nov 2026

Last reviewed 16 Nov 2026.