Skip to content

Conversation

@nakayukl-demo
Copy link
Contributor

@nakayukl-demo nakayukl-demo commented Nov 20, 2025

概要

AgentCore RuntimeのVPCネットワーク設定機能を追加し、プライベートネットワーク環境での動作をサポートしました。

変更内容

🚀 新機能

  • AgentCore Runtime VPC設定: PUBLIC/PRIVATEネットワークモードの選択が可能
  • VPCネットワーク構成: 既存VPCとサブネットを指定してAgentCore Runtimeをデプロイ

🔧 実装詳細

新規パラメータ

  • agentCoreNetworkType: PUBLIC (デフォルト) / PRIVATE
  • agentCoreVpcId: 使用するVPC ID
  • agentCoreSubnetIds: 使用するサブネットIDリスト

コード変更

  • stack-input.ts: VPC設定パラメータとバリデーション追加
  • agent-core-stack.ts: VPC設定パラメータの受け渡しとCloudFormation出力
  • generic-agent-core.ts: VPC/セキュリティグループ作成ロジック実装

⚠️ 重要な設計判断

セキュリティグループのRetain設定

VPCモード使用時、セキュリティグループにRemovalPolicy.RETAINを設定:

  • AgentCore Runtimeが作成するAWSマネージドENIがセキュリティグループを参照
  • CloudFormationではマネージドENI削除前にセキュリティグループを削除不可
  • マネージドENIの自動削除完了後(長い場合数時間)に手動削除が必要
  • CloudFormation出力でセキュリティグループIDを表示し、手動削除を促進

📚 ドキュメント更新

  • 日本語/英語/韓国語: AgentCore Runtime VPC設定セクション追加
  • 使用場面: 社内システム連携、プライベートデータベースアクセス等
  • AZ制限: リージョンごとのサポート対象AZ情報
  • NAT Gateway要件: MCPサーバーインストール用インターネットアクセス
  • 手動削除手順: AgentCore無効化後のスタック削除方法

🧪 テスト

  • スナップショットテスト更新済み
  • AgentCore設定変更フローテスト: なし → PUBLIC → PRIVATE → PUBLIC → なし
  • Generic RuntimeとAgentBuilder Runtime両方の動作確認
  • セキュリティグループの適切なタグ付けと保持確認
  • VPC内データベース接続テスト: プライベートサブネット内のSQL Server RDSに対してMSSQL MCPサーバー経由でのデータベースアクセス動作確認済み
"mssql": {
  "command": "npx",
  "args": ["@wener/mssql-mcp", "--stdio"],
  "env": {
    "MSSQL_SERVER": "xxxxxxxx.xxxxxxxx.us-east-1.rds.amazonaws.com",
    "MSSQL_DATABASE": "xxxxxxxx",
    "MSSQL_USER": "xxxxxxxx",
    "MSSQL_PASSWORD": "xxxxxxxx"
  },
  "metadata": {
    "category": "Database",
    "description": "Microsoft SQL Server database access for AgentBuilder"
  }
}

使用例

// parameter.ts
const envs: Record<string, Partial<StackInput>> = {
  dev: {
    createGenericAgentCoreRuntime: true,
    agentBuilderEnabled: true,
    agentCoreNetworkType: 'PRIVATE',
    agentCoreVpcId: 'vpc-xxxxxxxxx',
    agentCoreSubnetIds: ['subnet-xxxxxxxxx', 'subnet-yyyyyyyyy'],
  },
};

影響範囲

  • 既存のPUBLICモードは後方互換
  • VPCモードはデフォルトでは無効(PUBLICがデフォルト)
  • セキュリティグループの手動削除が必要(コスト影響なし)

参考リンク

参考動画

Copy link
Contributor

@tbrand tbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agentCoreNetworkType の仕様について質問です。VpcId と SubnetIds がともに指定されている場合、自動で private 判定されるというロジックではだめでしょうか?また、PUBLIC、PRIVATE という文字列による指定である必要はありますか?例えば、これ以上選択肢が増える見込みがない場合、boolean で良いのではないでしょうか?

@nakayukl-demo
Copy link
Contributor Author

VpcId と SubnetIds がともに指定されている場合、自動で private 判定されるというロジックではだめでしょうか?

いいですね!そちらの方がシンプルで開発者の設定が少なくて良いと思います。
もともと、agentcore の network configuration の 引数にそのまま PUBLIC と PRIVATE で渡せるってだけだったので、ご指摘のように変えようと思います。しばしお待ちを。

@nakayukl-demo
Copy link
Contributor Author

修正してみました。まだテストとドキュメントを修正途中なのでマージは待っていただけると嬉しいのですが、1 点、GenU の cdk.json や parameter.ts を stack に波及させる部分の設計意図に沿っているか判断できない部分がありご質問です。

例えば、これ以上選択肢が増える見込みがない場合、boolean で良いのではないでしょうか?

この修正のために、parameter.ts の getParam 内で、 isAgentCoreNetworkPrivate: boolean を agentCoreVpcId, agentCoreSubnetIds から自動で判定するロジックを実装しています。そして、その isAgentCoreNetworkPrivate を agent core runtime の stack に渡す仕組みです。変換ロジックの差し込み場所がこの位置で正しそうかコメントいただけますと幸いです。

私の処理の理解は以下の通りで、これが正しそうなら、今差し込んでいる場所で良さそうだなと思いつつ。

mermaid-diagram-2025-11-29-200200

@tbrand
Copy link
Contributor

tbrand commented Dec 1, 2025

https://github.com/aws-samples/generative-ai-use-cases/pull/1360/files#diff-7222bc11938073d7b5cdde6d47c378c7dfcebe6d024af0e6ab00d252a62a9820R82
こちらのことでしょうか?であれば、ここで良いと思います。

@nakayukl-demo
Copy link
Contributor Author

細かいところで、恐縮でした。ありがとございます。
では、このままテスト進めます。

- Add VPC network configuration section to DEPLOY_OPTION.md
- Include AZ support requirements with AWS official documentation link
- Add NAT Gateway requirements for MCP server installation
- Add manual stack deletion procedure for AgentCore
- Include both Generic Runtime and AgentBuilder Runtime settings
- Add use case scenarios for VPC mode
- Include agentBuilderEnabled in configuration examples
- Add AZ support requirements with official documentation link
- Add NAT Gateway requirements for MCP server installation
- Remove agentCoreNetworkType parameter from user input
- Add isAgentCoreNetworkPrivate computed in parameter.ts
- Automatically set to true when both agentCoreVpcId and agentCoreSubnetIds are provided
- Add validation to ensure VPC settings are provided together
- Update GenericAgentCore to use boolean flag instead of enum
- Applies to both Generic Runtime and Agent Builder Runtime
- Fix validation logic to properly handle null values for agentCoreSubnetIds
- Remove agentCoreNetworkType parameter (network mode is now auto-detected)
- Update documentation to reflect the simplified VPC configuration
- Add isAgentCoreNetworkPrivate computed property
@nakayukl-demo
Copy link
Contributor Author

nakayukl-demo commented Dec 3, 2025

@tbrand
修正、テスト完了し、チェックとおりました。ご確認をお願いします。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants