Let Your AI Agent Write Least-Privilege IAM Policies A LocalStack experiment found that an AI agent using Claude Code and the LocalStack MCP server could replace an intentionally over-broad Lambda IAM role — one granting every action across nine AWS services — with a least-privilege policy. The agent used the localstack-iam-policy-analyzer tool to read IAM enforcement denials, generate a policy grouped by resource, then enabled ENFORCED mode and verified the app still worked while the role could no longer reach unrelated resources. The result matters because LocalStack's default DISABLED mode accepts AWS requests without checking IAM, letting overly broad policies like dynamodb:* with Resource: "*" go unnoticed during local development. IAM policies often start out too broad. A Lambda function needs to read a table, but the first deployment fails with AccessDenied . Someone adds dynamodb: with Resource: " " to fix it. The policy works, so no one revisits it. Soon, the function can access far more than it needs. Writing a narrow policy by hand takes time. You must find every API call, map it to an IAM action, and identify the right resource ARN. If you miss one, the app fails only when that code path runs. We wanted to see whether an AI agent could do this work. We gave Claude Code https://www.claude.com/product/claude-code access to the LocalStack MCP server https://github.com/localstack/localstack-mcp-server and an intentionally insecure serverless app. Its Lambda role allowed every action in nine AWS services. We asked the agent to replace that policy with a least-privilege policy. The agent used the IAM Policy Analyzer to find the required permissions. It reviewed the generated policy against the code, enabled IAM enforcement, and verified that the app still worked. It also proved that the role could no longer access unrelated resources. By default, LocalStack accepts AWS requests without checking IAM. This keeps local development fast, but it also hides broken or overly broad policies. IAM policy enforcement https://docs.localstack.cloud/aws/capabilities/security-testing/iam-policy-enforcement/ makes LocalStack evaluate the policies that apply to each request. These include identity and resource policies, permission boundaries, and service control policies. If no policy allows a request, LocalStack returns AccessDenied . This check also applies to Lambda functions. LocalStack gives each function temporary credentials for its execution role. Its SDK calls arrive as assumed-role/