The Complete Production SOP: How to Deploy and Run AWS IAM Least-Privilege Policies & Access Analyzer in Autonomous AI Agents
Production SOP to install and run the AWS IAM Least-Privilege Policy skill in Codex, Claude Code, Cursor, and Windsurf. Eliminate wildcards deterministically.
Technical Overview & Architectural Context
Autonomous coding agents frequently default to over-permissive wildcard statements like `Action: "s3:*"` or `Resource: "*"` when provisioning cloud infrastructure via Terraform, CloudFormation, or CDK. These broad permissions create critical security vulnerabilities, fail cloud security posture management (CSPM) audits, and open accounts to privilege escalation. Left unconstrained, LLMs struggle to map exact sub-resource ARNs (such as distinguishing bucket ARN from object ARN) and routinely omit essential condition keys like `aws:SecureTransport`. The `aws-iam-least-privilege-policy` skill converts fuzzy intent into deterministic policy generation. By codifying strict parameter boundaries, requiring explicit API actions, demanding condition blocks, enforcing permission boundaries, and leveraging AWS IAM Access Analyzer validation APIs, this skill guarantees that Codex, Claude Code, Cursor, and Windsurf generate zero-wildcard, audit-compliant IAM artifacts.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the SKILL.md manifest into your global or project-level agent configuration directory.
Autonomous agent runtimes discover contextual skills by scanning `.agents/skills` or `.claude/skills` directories. Injecting the verified SKILL.md manifest equips the agent's system prompt with frontmatter triggers, permission boundaries (`fs_read: true`, `fs_write: 'workspace'`), and execution rules that prevent broad wildcard authorizations.
mkdir -p .agents/skills/aws-iam-least-privilege-policy && cat << 'EOF' > .agents/skills/aws-iam-least-privilege-policy/SKILL.md
---
name: "aws-iam-least-privilege-policy"
description: "Author granular, least-privilege IAM policies and eliminate wildcards using IAM Access Analyzer."
metadata:
author: "AWS"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "write least privilege iam policy"
- "generate iam policy access analyzer"
- "configure iam permission boundary"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# AWS IAM Least-Privilege Policies & Access Analyzer
Constructs AWS IAM policies: scoping Action, Resource, and Condition blocks (aws:PrincipalOrgID, s3:prefix), role assumption trust policies, detecting unused permissions with Access Analyzer, and permission boundaries.
## Execution SOP & Rules
1. Avoid Action: '*' and Resource: '*' wildcards; explicitly enumerate required API calls.
2. Use Condition blocks to enforce TLS (aws:SecureTransport: true) and IP CIDR restrictions.
3. Attach Permission Boundaries to developer roles to prevent privilege escalation.
4. Validate policy syntax with aws accessanalyzer validate-policy --policy-document file://policy.json.
EOF---
name: "aws-iam-least-privilege-policy"
description: "Author granular, least-privilege IAM policies and eliminate wildcards using IAM Access Analyzer."
metadata:
author: "AWS"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "write least privilege iam policy"
- "generate iam policy access analyzer"
- "configure iam permission boundary"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Use workspace-relative skill directories (.agents/skills) to keep project-specific IAM boundaries tracked in Git while saving LLM tokens compared to monolithic system prompts.
Ensure permissions.shell_exec remains false in the frontmatter if running in restricted environments; agent validation can run via explicit external hooks.
Environment Secrets & Dependency Validation
Configure local AWS credentials and verify policy validation utilities without exposing keys.
To enable self-healing and linting verification, ensure the local environment has read-only access to AWS Access Analyzer CLI methods (`accessanalyzer:ValidatePolicy`). Use AWS profiles or short-lived federated credentials rather than hardcoding static keys.
aws configure get aws_access_key_id > /dev/null && echo "AWS CLI credentials available" || echo "Warning: AWS credentials missing for policy validation"AWS_REGION=us-east-1
AWS_PROFILE=audit-role
# Never commit plaintext AWS_SECRET_ACCESS_KEY hereConfigure AWS_STS_REGIONAL_ENDPOINTS=regional in your workspace shell to accelerate IAM validation API roundtrips.
Do not pass IAM secret access keys into chat prompts; agent transcripts may be logged or cached.
Intent Matching & Trigger Invocation
Trigger the deterministic SOP using exact keyword prompts.
When invoking Codex, Claude Code, Cursor, or Windsurf, match one of the declared triggers (`write least privilege iam policy`, `generate iam policy access analyzer`, `configure iam permission boundary`). The agent activates the SOP, prompting it to request exact resource ARNs and construct segmented policy statements.
claude "write least privilege iam policy for an S3 export worker requiring bucket list and object get/put in production"{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowBucketListScoped",
"Effect": "Allow",
"Action": ["s3:ListBucket"],
"Resource": "arn:aws:s3:::company-data-exports-prod",
"Condition": {
"StringLike": {
"s3:prefix": ["reports/*", "logs/*"]
}
}
},
{
"Sid": "AllowObjectReadWriteScoped",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::company-data-exports-prod/*"
},
{
"Sid": "EnforceSecureTransportOnly",
"Effect": "Deny",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::company-data-exports-prod",
"arn:aws:s3:::company-data-exports-prod/*"
],
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
]
}Always specify partition, account ID, and resource path prefix in your prompt so the agent avoids falling back to wildcard ARNs.
Listing a bucket requires bucket-level ARN (`arn:aws:s3:::bucket`), while object operations require wildcards on paths (`arn:aws:s3:::bucket/*`). Mixing these in a single statement causes AWS authorization failures.
Verification, Linting & Output Quality Gate
Execute Access Analyzer policy validation to detect syntax errors and security warnings.
The skill mandates executing `aws accessanalyzer validate-policy` against any generated JSON policy file before marking a task complete. This catches malformed actions, missing condition keys, and security warnings like privilege escalation risks.
aws accessanalyzer validate-policy --policy-document file://policies/s3-export-policy.json --policy-type IDENTITY_POLICY --output json | jq '.findings'{
"findings": []
}In CI/CD or agent pre-commit hooks, set jq to exit with code 1 if .findings contains any object with issueCode != null.
Access Analyzer returns code 0 even if policy validation findings are present. Always parse the JSON findings array to catch warnings.
Real-World Scenario: Microservice Cross-Account DynamoDB & KMS Least-Privilege Role
“write least privilege iam policy for an ECS order-processing task in account 111122223333 that needs to query and write to DynamoDB table 'Orders' in us-east-1, encrypt with KMS key 'arn:aws:kms:us-east-1:111122223333:key/a1b2c3d4-e5f6', and enforce a strict permission boundary.”
Runtime Troubleshooting & Failure Modes
Root Cause: Agent generated trailing commas or unescaped quotes in the JSON policy definition, violating standard RFC 8259 JSON syntax expected by the IAM Access Analyzer API.
jq empty policies/s3-export-policy.json && aws accessanalyzer validate-policy --policy-document file://policies/s3-export-policy.json --policy-type IDENTITY_POLICYRoot Cause: The agent runner or host AWS profile lacks the IAM permission accessanalyzer:ValidatePolicy required to perform automated least-privilege syntax linting.
aws iam attach-user-policy --user-name agent-executor --policy-arn arn:aws:iam::aws:policy/AWSAccessAnalyzerComputeServiceRolePolicy || echo '{"Effect":"Allow","Action":"accessanalyzer:ValidatePolicy","Resource":"*"}'Frequently Asked Questions (AWS IAM Least-Privilege Policies & Access Analyzer SOP)
Q:Can I use AWS IAM Least-Privilege Policies & Access Analyzer across Codex, Claude Code, and Cursor simultaneously?
Yes. This skill uses the universal SKILL.md specification. Whether invoking via Claude Code CLI (`claude`), Codex Desktop, Cursor agent rules, or Windsurf Cascades, placing the skill in your project or agent repository guarantees uniform execution.
Q:How does this skill prevent wildcards when generating complex IAM policies?
The frontmatter SOP rules explicitly forbid wildcard tokens ('*') for Action and Resource elements unless structurally required by AWS (e.g., s3:ListAllMyBuckets). It forces the agent to resolve specific service namespaces and ARNs before completing generation.
Q:Does running policy validation incur AWS billing charges?
No. The AWS IAM Access Analyzer `validate-policy` API is free of charge and provides real-time policy linting without requiring active paid analyzer analyzers to be configured in your account.
Ready to equip your autonomous agent with AWS IAM Least-Privilege Policies & Access Analyzer?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.