【AWS re:Invent 2025】コードからIAMポリシーを生成するIAM Policy Autopilotを試してみました

記事タイトルとURLをコピーする

こんにちは。
アプリケーションサービス部、DevOps担当の兼安です。

今週はいよいよAWS re:Invent 2025ですね。
本格的に始まる前ではありますが、早速多くの新サービスやアップデートが発表されています。

そんな中、コードからIAMポリシーを生成するIAM Policy Autopilotを発表されました。
アプリケーションエンジニアとして非常に興味深いサービスですので、早速触ってみました。

IAM Policy Autopilotとは

IAM Policy Autopilotは、コードからIAMポリシーを自動生成するコマンドラインツールでありMCPサーバーです。

IAM Policy Autopilotのイメージ

本サービスの発表に関する記事はこちらです。

aws.amazon.com

記事中にもありますが、IAM Policy Autopilotは、IAMポリシーを生成しますが、現時点ではリソースポリシー・アクセス権限の境界・RCP・SCPは未対応とのことです。
IAM Policy Autopilotは、コマンドとして実行することもできますし、MCPサーバーとして動作させることもできます。

IAM Policy Autopilotの使い方

IAM Policy Autopilotの使い方は、同サービスのGitHubリポジトリに記載されています。

github.com

コマンドで実行する場合

コマンドで実行する場合は、uvxコマンドを使えばインストールなしで即実行できます。
uvxを使わない場合は、pipcurlでインストールして使用します。
私はuvxを使って実行しました。

$ uvx iam-policy-autopilot

Installed 1 package in 1ms
Generate IAM policies from source code and fix AccessDenied errors

Usage: iam-policy-autopilot <COMMAND>

Commands:
  fix-access-denied  Fix AccessDenied errors by analyzing and optionally applying IAM policy changes
  generate-policies  Generates complete IAM policy documents from source files
  mcp-server     Start MCP server
  help         Print this message or the help of the given subcommand(s)

Options:
  -h, --help   Print help (see more with '--help')
  -V, --version  Print version

ポリシーの生成を試したいので、generate-policiesコマンドを実行します。
使い方を知りたいので-hオプションを付与して実行します。

$ uvx iam-policy-autopilot generate-policies -h

Generates complete IAM policy documents from source files

Usage: iam-policy-autopilot generate-policies [OPTIONS] <SOURCE_FILES>...

Arguments:
  <SOURCE_FILES>...  Source files to analyze for SDK method extraction

Options:
  -p, --pretty
      Format JSON output with indentation for readability
  -l, --language <LANGUAGE>
      Override programming language detection
    --full-output
      Output full ExtractedMethods instead of simplified operations
  -r, --region <REGION>
      AWS region [default: *]
  -a, --account <ACCOUNT>
      AWS account ID [default: *]
    --upload-policies [<UPLOAD_POLICIES>]
      Upload generated policies to AWS IAM with optional custom name prefix
    --minimize-policy-size
      Enable minimal policy size by allowing cross-service action merging
    --disable-cache
      Disable file system caching for service references
    --service-hints <SERVICE_HINTS>...
      Filter extracted SDK calls to specific AWS services
  -h, --help
      Print help (see more with '--help')

基本的な使い方は、Usage: iam-policy-autopilot generate-policies [OPTIONS] <SOURCE_FILES>...ですね。
<SOURCE_FILES>なので、ディレクトリではなくファイルを指定する必要があります。

ファイルを指定して実行すると、確かにポリシーが生成されます。

$ uvx iam-policy-autopilot generate-policies example.py

{"Policies":[{"Policy":{"Id":"IamPolicyAutopilot","Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["kms:Decrypt","kms:GenerateDataKey"],"Resource":["arn:aws:kms:*:*:key/*"],"Condition":{"StringLike":{"kms:ViaService":["s3.*.amazonaws.com"]}}・・・省略

見づらいので、-pオプションを付与して実行します。

$ uvx iam-policy-autopilot generate-policies -p example.py

{
  "Policies": [
  {
    "Policy": {
    "Id": "IamPolicyAutopilot",
    "Version": "2012-10-17",
    "Statement": [
      {
      "Effect": "Allow",
      "Action": [
        "kms:Decrypt",
        "kms:GenerateDataKey"
      ],
      "Resource": [
        "arn:aws:kms:*:*:key/*"
      ],
      "Condition": {
        "StringLike": {
        "kms:ViaService": [
          "s3.*.amazonaws.com"
        ]
        }
      }
      },
      省略

ポリシーが生成されたので、これをIaCなどに組み込んで利用できますね。
オプションの指定によって、IAMに直接アップロードしたりもできるようです。
ただ、ポリシーの生成の仕方にちょっと癖を感じます。
ある意味、細かく指定してくれているようにも思えますが、しばらく吟味が必要そうです。

MCPサーバーで利用する場合

MCPサーバーで利用する場合は、各種MCPクライアントに登録して利用します。
KiroやKiro CLIの場合は、.kiro/settings/mcp.jsonにMCPサーバーの情報を登録します。
先ほどと同じくuvxでMCPサーバーを起動するとしたら、GitHubリポジトリの記述に従って以下のように記載します。

{
  "mcpServers": {
  "iam-policy-autopilot": {
    "command": "uvx",
    "args": ["iam-policy-autopilot", "mcp-server"],
    "env": {
    "AWS_PROFILE": "your-profile-name",
    "AWS_REGION": "us-east-1"
    },
    "disabled": false,
    "autoApprove": []
  }
  }
}

このように記載した上で、Kiro CLIを起動します。

WARNING: Both .kiro and .amazonq folders found in workspace. Using .kiro configuration.
✓ iam-policy-autopilot loaded in 0.73 s

⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀   ⢀⣴⣶⣶⣦⡀⠀⠀⠀⢀⣴⣶⣦⣄⡀⠀⠀⢀⣴⣶⣶⣦⡀⠀⠀⢀⣴⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣄⡀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣶⣶⣶⣶⣶⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀  ⢰⣿⠋⠁⠈⠙⣿⡆⠀⢀⣾⡿⠁⠀⠈⢻⡆⢰⣿⠋⠁⠈⠙⣿⡆⢰⣿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠻⣦⠀⠀⠀⠀⣴⡿⠟⠋⠁⠀⠀⠀⠈⠙⠻⢿⣦⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀  ⢸⣿⠀⠀⠀⠀⣿⣇⣴⡿⠋⠀⠀⠀⢀⣼⠇⢸⣿⠀⠀⠀⠀⣿⡇⢸⣿⠀⠀⠀⢠⣤⣤⣤⣤⣄⠀⠀⠀⠀⣿⡆⠀⠀⣼⡟⠀⠀⠀⠀⣀⣀⣀⠀⠀⠀⠀⢻⣧⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀  ⢸⣿⠀⠀⠀⠀⣿⡿⠋⠀⠀⠀⢀⣾⡿⠁⠀⢸⣿⠀⠀⠀⠀⣿⡇⢸⣿⠀⠀⠀⢸⣿⠉⠉⠉⣿⡇⠀⠀⠀⣿⡇⠀⣼⡟⠀⠀⠀⣰⡿⠟⠛⠻⢿⣆⠀⠀⠀⢻⣧⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀  ⢸⣿⠀⠀⠀⠀⠙⠁⠀⠀⢀⣼⡟⠁⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡇⢸⣿⠀⠀⠀⢸⣿⣶⣶⡶⠋⠀⠀⠀⠀⣿⠇⢰⣿⠀⠀⠀⢰⣿⠀⠀⠀⠀⠀⣿⡆⠀⠀⠀⣿⡆
⠀⠀⠀⠀⠀⠀⠀  ⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠹⣷⡀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡇⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣼⠟⠀⢸⣿⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⣿⡇⠀⠀⠀⣿⡇
⠀⠀⠀⠀⠀⠀⠀  ⢸⣿⠀⠀⠀⠀⠀⣠⡀⠀⠀⠹⣷⡄⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡇⢸⣿⠀⠀⠀⠀⣤⣄⠀⠀⠀⠀⠹⣿⡅⠀⠀⠸⣿⠀⠀⠀⠸⣿⠀⠀⠀⠀⠀⣿⠇⠀⠀⠀⣿⠇
⠀⠀⠀⠀⠀⠀⠀  ⢸⣿⠀⠀⠀⠀⣾⡟⣷⡀⠀⠀⠘⣿⣆⠀⠀⢸⣿⠀⠀⠀⠀⣿⡇⢸⣿⠀⠀⠀⠀⣿⡟⣷⡀⠀⠀⠀⠘⣿⣆⠀⠀⢻⣧⠀⠀⠀⠹⣷⣦⣤⣤⣾⠏⠀⠀⠀⣼⡟
⠀⠀⠀⠀⠀⠀⠀  ⢸⣿⠀⠀⠀⠀⣿⡇⠹⣷⡀⠀⠀⠈⢻⡇⠀⢸⣿⠀⠀⠀⠀⣿⡇⢸⣿⠀⠀⠀⠀⣿⡇⠹⣷⡀⠀⠀⠀⠈⢻⡇⠀⠀⢻⣧⠀⠀⠀⠀⠉⠉⠉⠀⠀⠀⠀⣼⡟
⠀⠀⠀⠀⠀⠀⠀  ⠸⣿⣄⡀⢀⣠⣿⠇⠀⠙⣷⡀⠀⢀⣼⠇⠀⠸⣿⣄⡀⢀⣠⣿⠇⠸⣿⣄⡀⢀⣠⣿⠇⠀⠙⣷⡀⠀⠀⢀⣼⠇⠀⠀⠀⠻⣷⣦⣄⡀⠀⠀⠀⢀⣠⣴⣾⠟
⠀⠀⠀⠀⠀⠀⠀  ⠀⠈⠻⠿⠿⠟⠁⠀⠀⠀⠈⠻⠿⠿⠟⠁⠀⠀⠈⠻⠿⠿⠟⠁⠀⠀⠈⠻⠿⠿⠟⠁⠀⠀⠀⠈⠻⠿⠿⠟⠁⠀⠀⠀⠀⠀⠈⠙⠻⠿⠿⠿⠿⠟⠋⠁

╭─────────────────────────────── Did you know? ────────────────────────────────╮
│                                        │
│   Enable workspace checkpoints to snapshot & restore changes. Just run   │
│         kiro-cli settings chat.enableCheckpoint true         │
│                                        │
╰──────────────────────────────────────────────────────────────────────────────╯

Model: Auto (/model to change)

iam-policy-autopilot loadedと表示され、MCPサーバーが起動しました。
プロンプトを入力して、IAMポリシーの生成を指示してみます。

> example.pyに必要なIAMポリシーを生成してください。  

> IAMポリシーを生成するために、まずファイルの内容を確認します。  
Reading file: example.py, all lines (using tool: read)
 ✓ Successfully read 8775 bytes from example.py
 - Completed in 0.0s

Kiro CLIがファイルを読み込み、割愛しますがこの後リージョンやアカウントIDを聞いてきました。
回答すると、IAMポリシーの生成が始まります。
from mcp server: iam-policy-autopilotと表示され、IAM Policy Autopilotが呼び出されていることがわかります。

Running tool generate_application_policies with the param (from mcp server: iam-policy-autopilot)
 ⋮  {
 ⋮  "SourceFiles": [
 ⋮    "example.py"
 ⋮  ],
 ⋮  "Account": "アカウントID",
 ⋮  "Region": "ap-northeast-1",
 ⋮  "ServiceHints": [
 ⋮    "s3",
 ⋮    "dynamodb"
 ⋮  ]
 ⋮  }

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

> y

 - Completed in 1.94s

> IAMポリシーを生成しました。  以下の内容をご確認ください。  

json
{
  "Id": "IamPolicyAutopilot",
  "Version": "2012-10-17",
  "Statement": [
  {
    "Effect": "Allow",
    "Action": [
    "kms:Decrypt",
    "kms:GenerateDataKey"
    ],
    "Resource": [
    "arn:aws:kms:ap-northeast-1:アカウントID:key/*"
    ],
    "Condition": {
    "StringEquals": {
      "kms:ViaService": [
      "s3.ap-northeast-1.amazonaws.com"
      ]
    }
    }
  },
  省略

生成されたIAMポリシーはコマンドで実行した場合と同様の内容でした。
IAMポリシーは、CloudFormationテンプレートの生成を指示するとファイルに出力してくれました。

> そのポリシーからCloudFormationテンプレートを生成してください。  

まとめ

以上、IAM Policy Autopilotの紹介と使い方でした。
便利そうなので、今後使い込んでみてまたレポートしたいと思います。

兼安 聡(執筆記事の一覧)

アプリケーションサービス部 DS3課所属
2025 Japan AWS Top Engineers (AI/ML Data Engineer)
2025 Japan AWS All Certifications Engineers
2025 AWS Community Builders
Certified ScrumMaster
PMP
広島在住です。今日も明日も修行中です。