Skip to content

Commit c536f67

Browse files
committed
v1.0.10
1 parent 6154baf commit c536f67

59 files changed

Lines changed: 1008 additions & 160 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# my_aws_tools
22

33
**Author:** r3-yamauchi
4-
**Version:** 1.0.9
4+
**Version:** 1.0.10
55
**Type:** tool
66

77
English | [Japanese](https://github.com/r3-yamauchi/dify-my-aws-tools-plugin/blob/main/readme/README_ja_JP.md)
@@ -59,6 +59,8 @@ Included tools:
5959
- Agentcore Event Manager
6060
- Agentcore Runtime
6161
- Agentcore Observability
62+
- Get Credentials
63+
- STS AssumeRole
6264

6365
The source code of this plugin is available in the [GitHub repository](https://github.com/r3-yamauchi/dify-my-aws-tools-plugin).
6466

@@ -667,6 +669,40 @@ yaml_content: |
667669
}
668670
```
669671

672+
- **Get Credentials**: Retrieves AWS credentials from boto3.Session. Returns access key, secret key, and session token in JSON format using the specified profile and region. If `profile_name` or `region_name` is not specified, it uses the AWS Credential Provider Chain (environment variables, ~/.aws/credentials, IAM roles, etc.) to obtain default credentials. When running on EC2 instances or ECS tasks, it can automatically retrieve temporary credentials from instance profiles or task roles.
673+
674+
```json
675+
{
676+
"profile_name": "development",
677+
"region_name": "ap-northeast-1"
678+
}
679+
```
680+
681+
```json
682+
{}
683+
```
684+
(Retrieve default credentials without parameters)
685+
686+
- **STS AssumeRole**: Uses AWS STS to assume an IAM role and retrieve temporary credentials. Use this for cross-account access or privilege escalation. Supports advanced configurations such as MFA authentication, external ID, and session policies. The retrieved credentials are returned in a format compatible with the Get Credentials tool.
687+
688+
```json
689+
{
690+
"role_arn": "arn:aws:iam::123456789012:role/MyRole",
691+
"role_session_name": "DifySession",
692+
"duration_seconds": 3600
693+
}
694+
```
695+
696+
```json
697+
{
698+
"role_arn": "arn:aws:iam::123456789012:role/CrossAccountRole",
699+
"role_session_name": "CrossAccountSession",
700+
"external_id": "unique-external-id-123",
701+
"serial_number": "arn:aws:iam::123456789012:mfa/user",
702+
"token_code": "123456"
703+
}
704+
```
705+
670706
## Privacy Policy
671707

672708
The plugin is designed to interact with AWS services (such as Bedrock, Lambda, S3, and DynamoDB) on your behalf. It does not collect analytics or telemetry beyond what is required to fulfill the tool invocations you issue.

manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.0.9
1+
version: 1.0.10
22
type: plugin
33
author: r3-yamauchi
44
name: my_aws_tools

provider/my_aws_tools.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ tools:
8383
- tools/agentcore/agentcore_observability.yaml
8484
- tools/agentcore/agentcore_code_interpreter.yaml
8585
- tools/agentcore/agentcore_code_interpreter_files.yaml
86+
- tools/get_credentials.yaml
87+
- tools/sts_assume_role.yaml
8688
extra:
8789
python:
8890
source: provider/my_aws_tools.py

readme/README_ja_JP.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# my_aws_tools
22

33
**Author:** r3-yamauchi
4-
**Version:** 1.0.9
4+
**Version:** 1.0.10
55
**Type:** tool
66

77
英語版ドキュメントはリポジトリ直下の `README.md` を参照してください。
@@ -59,6 +59,8 @@
5959
- Agentcore Event Manager
6060
- Agentcore Runtime
6161
- Agentcore Observability
62+
- Get Credentials
63+
- STS AssumeRole
6264

6365
## ライセンスとクレジット
6466

@@ -662,3 +664,37 @@ yaml_content: |
662664
"name": "run-001"
663665
}
664666
```
667+
668+
- **Get Credentials**: boto3.Session から AWS 認証情報を取得します。指定したプロファイルとリージョンを使用して、アクセスキー、シークレットキー、セッショントークンを JSON 形式で返却します。`profile_name` や `region_name` を指定しない場合は、AWS Credential Provider Chain(環境変数、~/.aws/credentials、IAM ロールなど)を使用してデフォルトの認証情報を取得します。EC2 インスタンスや ECS タスクで実行する場合は、インスタンスプロファイルやタスクロールから一時的な認証情報を自動的に取得できます。
669+
670+
```json
671+
{
672+
"profile_name": "development",
673+
"region_name": "ap-northeast-1"
674+
}
675+
```
676+
677+
```json
678+
{}
679+
```
680+
(パラメータなしでデフォルト認証情報を取得)
681+
682+
- **STS AssumeRole**: AWS STS を使用して IAM ロールを引き受け、一時的な認証情報を取得します。クロスアカウントアクセスや権限昇格が必要な場合に使用します。MFA 認証、外部 ID、セッションポリシーなどの高度な設定にも対応しています。取得した認証情報は Get Credentials ツールと互換性のある形式で返却されます。
683+
684+
```json
685+
{
686+
"role_arn": "arn:aws:iam::123456789012:role/MyRole",
687+
"role_session_name": "DifySession",
688+
"duration_seconds": 3600
689+
}
690+
```
691+
692+
```json
693+
{
694+
"role_arn": "arn:aws:iam::123456789012:role/CrossAccountRole",
695+
"role_session_name": "CrossAccountSession",
696+
"external_id": "unique-external-id-123",
697+
"serial_number": "arn:aws:iam::123456789012:mfa/user",
698+
"token_code": "123456"
699+
}
700+
```

tools/agentcore/agentcore_code_interpreter.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ parameters:
4444
ja_JP: 必要に応じてプロバイダー設定を上書きするシークレットキー。
4545
form: form
4646

47+
- name: aws_session_token
48+
type: string
49+
required: false
50+
label:
51+
en_US: AWS Session Token
52+
ja_JP: AWS セッショントークン
53+
human_description:
54+
en_US: AWS session token for temporary credentials (STS). Only supported in tool parameters, not at provider level.
55+
ja_JP: 一時的な認証情報(STS)用のセッショントークン。ツールパラメータのみでサポートされ、プロバイダーレベルではサポートされません。
56+
form: form
57+
4758
- name: aws_region
4859
type: string
4960
required: false

tools/agentcore/agentcore_code_interpreter_files.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
from my_aws_tools.utils.utils import resolve_aws_credentials
2626

2727
try:
28-
from bedrock_agentcore.code_interpreter import CodeInterpreterClient
28+
from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter as CodeInterpreterClient
2929
AGENTCORE_SDK_AVAILABLE = True
30-
except ImportError as exc: # pragma: no cover
30+
except ImportError: # pragma: no cover
3131
CodeInterpreterClient = None
3232
AGENTCORE_SDK_AVAILABLE = False
33-
print(f"Warning: bedrock-agentcore SDK import failed: {exc}")
3433

3534
try:
3635
import boto3
@@ -66,6 +65,8 @@ def _initialize_clients(self, tool_parameters: Dict[str, Any]) -> bool:
6665
"""
6766
Code Interpreter Client と S3 Client を初期化する
6867
68+
標準的な認証情報取得パターンを使用
69+
6970
Args:
7071
tool_parameters: ツールパラメータ
7172
@@ -75,20 +76,13 @@ def _initialize_clients(self, tool_parameters: Dict[str, Any]) -> bool:
7576
要件: 17.1, 17.2, 17.3, 17.4
7677
"""
7778
try:
78-
# AWS 認証情報を解決
79+
# 標準的な認証情報解決パターンを使用
7980
credentials = resolve_aws_credentials(self, tool_parameters)
8081
aws_region = credentials.get("aws_region") or 'us-east-1'
81-
aws_access_key_id = credentials.get("aws_access_key_id")
82-
aws_secret_access_key = credentials.get("aws_secret_access_key")
8382

8483
if AGENTCORE_SDK_AVAILABLE:
85-
# AK/SK が両方ある場合は環境変数経由で渡す
86-
if aws_access_key_id and aws_secret_access_key:
87-
os.environ['AWS_ACCESS_KEY_ID'] = aws_access_key_id
88-
os.environ['AWS_SECRET_ACCESS_KEY'] = aws_secret_access_key
89-
os.environ['AWS_REGION'] = aws_region
90-
91-
# CodeInterpreterClient を生成
84+
# CodeInterpreterClient は内部で boto3 を使用するため、
85+
# boto3 の標準認証チェーン(環境変数、~/.aws/credentials、IAMロールなど)が自動的に使用される
9286
self.code_interpreter_client = CodeInterpreterClient(region_name=aws_region)
9387
logger.info(f"Code Interpreter client initialized for region: {aws_region}")
9488
else:
@@ -97,15 +91,8 @@ def _initialize_clients(self, tool_parameters: Dict[str, Any]) -> bool:
9791

9892
# S3 Client を初期化
9993
if BOTO3_AVAILABLE:
100-
if aws_access_key_id and aws_secret_access_key:
101-
self.s3_client = boto3.client(
102-
's3',
103-
region_name=aws_region,
104-
aws_access_key_id=aws_access_key_id,
105-
aws_secret_access_key=aws_secret_access_key
106-
)
107-
else:
108-
self.s3_client = boto3.client('s3', region_name=aws_region)
94+
client_kwargs = build_boto3_client_kwargs(credentials)
95+
self.s3_client = boto3.client('s3', **client_kwargs)
10996
logger.info("S3 client initialized")
11097

11198
return True

tools/agentcore/agentcore_code_interpreter_files.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,17 @@ parameters:
365365
llm_description: AWS secret access key for authentication.
366366
form: form
367367

368+
- name: aws_session_token
369+
type: string
370+
required: false
371+
label:
372+
en_US: AWS Session Token
373+
ja_JP: AWS セッショントークン
374+
human_description:
375+
en_US: AWS session token for temporary credentials (STS). Only supported in tool parameters, not at provider level.
376+
ja_JP: 一時的な認証情報(STS)用のセッショントークン。ツールパラメータのみでサポートされ、プロバイダーレベルではサポートされません。
377+
form: form
378+
368379
extra:
369380
python:
370381
source: tools/agentcore/agentcore_code_interpreter_files.py

tools/agentcore/agentcore_event_manager.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
from bedrock_agentcore.memory import MemoryClient
2424

2525
AGENTCORE_SDK_AVAILABLE = True
26-
except ImportError as exc: # pragma: no cover - SDK 未導入環境に備える
26+
except ImportError: # pragma: no cover - SDK 未導入環境に備える
2727
MemoryClient = None
2828
AGENTCORE_SDK_AVAILABLE = False
29-
print(f"Warning: bedrock-agentcore SDK import failed: {exc}")
3029

3130
logger = logging.getLogger(__name__)
3231

@@ -54,19 +53,12 @@ def _initialize_memory_client(self, tool_parameters: dict[str, Any]) -> bool:
5453
return False
5554

5655
try:
57-
# 既存の resolve_aws_credentials を使用して認証情報を解決
56+
# 標準的な認証情報解決パターンを使用
5857
credentials = resolve_aws_credentials(self, tool_parameters)
5958
aws_region = credentials.get("aws_region") or "us-east-1"
60-
aws_access_key_id = credentials.get("aws_access_key_id")
61-
aws_secret_access_key = credentials.get("aws_secret_access_key")
6259

63-
# 明示的な AK/SK が渡された場合は環境変数経由で設定
64-
if aws_access_key_id and aws_secret_access_key:
65-
os.environ["AWS_ACCESS_KEY_ID"] = aws_access_key_id
66-
os.environ["AWS_SECRET_ACCESS_KEY"] = aws_secret_access_key
67-
os.environ["AWS_REGION"] = aws_region
68-
69-
# MemoryClient を初期化
60+
# MemoryClient は内部で boto3 を使用するため、
61+
# boto3 の標準認証チェーン(環境変数、~/.aws/credentials、IAMロールなど)が自動的に使用される
7062
self.memory_client = MemoryClient(region_name=aws_region)
7163
logger.info("AgentCore Memory client initialized successfully")
7264
return True

tools/agentcore/agentcore_event_manager.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@ parameters:
320320
llm_description: AWS secret access key for authentication.
321321
form: form
322322

323+
- name: aws_session_token
324+
type: string
325+
required: false
326+
label:
327+
en_US: AWS Session Token
328+
ja_JP: AWS セッショントークン
329+
human_description:
330+
en_US: AWS session token for temporary credentials (STS). Only supported in tool parameters, not at provider level.
331+
ja_JP: 一時的な認証情報(STS)用のセッショントークン。ツールパラメータのみでサポートされ、プロバイダーレベルではサポートされません。
332+
form: form
333+
323334
extra:
324335
python:
325336
source: tools/agentcore/agentcore_event_manager.py

tools/agentcore/agentcore_memory.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
from bedrock_agentcore.memory import MemoryClient
2222

2323
AGENTCORE_SDK_AVAILABLE = True
24-
except ImportError as exc: # pragma: no cover - SDK 未導入環境に備える
24+
except ImportError: # pragma: no cover - SDK 未導入環境に備える
2525
MemoryClient = None
2626
AGENTCORE_SDK_AVAILABLE = False
27-
print(f"Warning: bedrock-agentcore SDK import failed: {exc}")
2827

2928
logger = logging.getLogger(__name__)
3029

@@ -52,23 +51,22 @@ def _clean_id_parameter(self, value: str) -> str:
5251
return value
5352

5453
def _initialize_memory_client(self, tool_parameters: dict[str, Any]) -> bool:
55-
"""AWS 資格情報から MemoryClient を構築する."""
54+
"""
55+
AWS 資格情報から MemoryClient を構築する
56+
57+
標準的な認証情報取得パターンを使用し、boto3の認証チェーンに委譲する
58+
"""
5659
if not AGENTCORE_SDK_AVAILABLE:
5760
logger.error("AgentCore Memory SDK not available")
5861
return False
5962

6063
try:
64+
# 標準的な認証情報解決パターンを使用
6165
credentials = resolve_aws_credentials(self, tool_parameters)
6266
aws_region = credentials.get("aws_region") or "us-east-1"
63-
aws_access_key_id = credentials.get("aws_access_key_id")
64-
aws_secret_access_key = credentials.get("aws_secret_access_key")
65-
66-
# 明示的な AK/SK が渡された場合は環境変数経由で設定
67-
if aws_access_key_id and aws_secret_access_key:
68-
os.environ["AWS_ACCESS_KEY_ID"] = aws_access_key_id
69-
os.environ["AWS_SECRET_ACCESS_KEY"] = aws_secret_access_key
70-
os.environ["AWS_REGION"] = aws_region
7167

68+
# MemoryClient は内部で boto3 を使用するため、
69+
# boto3 の標準認証チェーン(環境変数、~/.aws/credentials、IAMロールなど)が自動的に使用される
7270
self.memory_client = MemoryClient(region_name=aws_region)
7371
logger.info("AgentCore Memory client initialized")
7472
return True

0 commit comments

Comments
 (0)