Resource-Based Policies for Functions
What you'll learn: How to control which AWS services, accounts, and principals can invoke your serverless functions using resource-based policies.
The Gatekeeper Model
Think of a resource-based policy as a bouncer at a club door. While IAM execution roles control what your function can do (outbound permissions), resource-based policies control who can invoke your function (inbound permissions). They're attached directly to the Lambda function itself, not to a user or role.
Core Components
A function's resource-based policy defines:
- Principal: Who can invoke? (specific AWS services like S3, SNS, API Gateway, or external AWS accounts)
- Action: What they can do (typically
lambda:InvokeFunction) - Condition: Optional constraints (source ARN, source account, IP ranges)
Common Use Cases
Cross-account access: Allow Account B to invoke a function in Account A without requiring Account B to assume a role first.
Service integrations: Grant S3 permission to invoke your function when objects are uploaded, or allow API Gateway to execute your function when endpoints are called.
Least privilege enforcement: Instead of wildcard permissions, specify exactly which S3 bucket or SNS topic can trigger the function using condition keys like aws:SourceArn.
Security Considerations
Always scope permissions narrowly. A policy allowing "any S3 bucket in any account" creates risk—an attacker controlling any bucket could trigger your function. Use aws:SourceAccount and aws:SourceArn conditions to lock down the exact resource that should have access.
Unlike execution roles (which you design), resource-based policies often get created automatically when you configure triggers through the console—review them carefully afterward.
Key Takeaway: Resource-based policies are the inbound firewall for your serverless functions—they determine who can invoke them, while execution roles determine what the function can access once running. Always apply least privilege with specific principals and condition constraints.