What You'll Learn
You'll discover how to add smart, context-aware "if-then" logic to IAM policies so permissions adapt based on real-world factors like who's asking, when, and from where.
The Core Idea
So far, your policies grant or deny permissions based on what action someone wants to perform on which resource. Condition keys let you add an extra layer: "grant this permission only if certain conditions are true."
Think of it like a bouncer at a club checking not just your ID, but also the time of day, whether you're on the guest list, and if you came with a VIP pass. Context matters.
Common Condition Keys
IAM policies can check context — the circumstances surrounding a request:
aws:SourceIp: Allow actions only from specific IP addresses (e.g., your office network)aws:CurrentTime: Restrict access to business hoursaws:MultiFactorAuthPresent: Require MFA to be enabled for sensitive operationsaws:PrincipalTag: Check tags assigned to the user or role making the requestaws:RequestedRegion: Limit actions to approved geographic regions
How It Works in Practice
Imagine a policy that says: "You can stop EC2 instances, but only if you're using MFA and it's between 9 AM and 5 PM and you're in US regions."
Each condition key reads information from the request context — metadata about who's making the call, when, how, and where. If all conditions match, the permission applies. If not, it's denied.
Why This Matters
Conditions transform static policies into dynamic security rules that adapt to risk. High-privilege actions can require MFA. After-hours access can be blocked. Geographic restrictions prevent data residency violations.
Key Takeaway:
Condition keys let you enforce "only if" logic in policies, using request context like IP address, time, MFA status, and tags to make permissions adaptive and secure.