Skip to content

Commit 82ee2a5

Browse files
committed
v1.0.3
1 parent aa716c8 commit 82ee2a5

11 files changed

Lines changed: 754 additions & 3 deletions

.difyignore

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Distribution / packaging
7+
.Python
8+
build/
9+
develop-eggs/
10+
dist/
11+
downloads/
12+
eggs/
13+
.eggs/
14+
lib/
15+
lib64/
16+
parts/
17+
sdist/
18+
var/
19+
wheels/
20+
share/python-wheels/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
MANIFEST
25+
26+
# PyInstaller
27+
# Usually these files are written by a python script from a template
28+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.nox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*.cover
46+
*.py,cover
47+
.hypothesis/
48+
.pytest_cache/
49+
cover/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
db.sqlite3
59+
db.sqlite3-journal
60+
61+
# Flask stuff:
62+
instance/
63+
.webassets-cache
64+
65+
# Scrapy stuff:
66+
.scrapy
67+
68+
# Sphinx documentation
69+
docs/_build/
70+
71+
# PyBuilder
72+
.pybuilder/
73+
target/
74+
75+
# Jupyter Notebook
76+
.ipynb_checkpoints
77+
78+
# IPython
79+
profile_default/
80+
ipython_config.py
81+
82+
# pyenv
83+
# For a library or package, you might want to ignore these files since the code is
84+
# intended to run in multiple environments; otherwise, check them in:
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
Pipfile.lock
93+
94+
# UV
95+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
96+
# This is especially recommended for binary packages to ensure reproducibility, and is more
97+
# commonly ignored for libraries.
98+
uv.lock
99+
100+
# poetry
101+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102+
# This is especially recommended for binary packages to ensure reproducibility, and is more
103+
# commonly ignored for libraries.
104+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105+
poetry.lock
106+
107+
# pdm
108+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109+
#pdm.lock
110+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111+
# in version control.
112+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
113+
.pdm.toml
114+
.pdm-python
115+
.pdm-build/
116+
117+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
118+
__pypackages__/
119+
120+
# Celery stuff
121+
celerybeat-schedule
122+
celerybeat.pid
123+
124+
# SageMath parsed files
125+
*.sage.py
126+
127+
# Environments
128+
.env
129+
.venv
130+
env/
131+
venv/
132+
ENV/
133+
env.bak/
134+
venv.bak/
135+
136+
# Spyder project settings
137+
.spyderproject
138+
.spyproject
139+
140+
# Rope project settings
141+
.ropeproject
142+
143+
# mkdocs documentation
144+
/site
145+
146+
# mypy
147+
.mypy_cache/
148+
.dmypy.json
149+
dmypy.json
150+
151+
# Pyre type checker
152+
.pyre/
153+
154+
# pytype static type analyzer
155+
.pytype/
156+
157+
# Cython debug symbols
158+
cython_debug/
159+
160+
# PyCharm
161+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
162+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
163+
# and can be added to the global gitignore or merged into this file. For a more nuclear
164+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
165+
.idea/
166+
167+
# Vscode
168+
.vscode/
169+
170+
# Git
171+
.git/
172+
.gitignore
173+
174+
# Mac
175+
.DS_Store
176+
177+
# Windows
178+
Thumbs.db

README.md

Lines changed: 4 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.2
4+
**Version:** 1.0.3
55
**Type:** tool
66

77
English | [Japanese](https://github.com/r3-yamauchi/dify-my-aws-tools-plugin/blob/main/readme/README_ja_JP.md)
@@ -36,6 +36,9 @@ Included tools:
3636
- S3 Operator
3737
- S3 File Uploader
3838
- S3 File Download
39+
- S3 List Buckets
40+
- S3 Create Bucket
41+
- S3 List Objects
3942
- SageMaker Chinese Toxicity Detector
4043
- SageMaker Text Rerank
4144
- SageMaker TTS

manifest.yaml

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

provider/my_aws_tools.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ tools:
5151
- tools/s3_operator.yaml
5252
- tools/s3_file_uploader.yaml
5353
- tools/s3_file_download.yaml
54+
- tools/s3_list_buckets.yaml
55+
- tools/s3_create_bucket.yaml
56+
- tools/s3_list_objects.yaml
5457
- tools/apply_guardrail.yaml
5558
- tools/nova_canvas.yaml
5659
- tools/transcribe_asr.yaml

readme/README_ja_JP.md

Lines changed: 4 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.2
4+
**Version:** 1.0.3
55
**Type:** tool
66

77
英語版ドキュメントはリポジトリ直下の `README.md` を参照してください。
@@ -32,6 +32,9 @@ AWS Tools プラグインは、複数の AWS サービスに基づくツール
3232
- S3 Operator
3333
- S3 File Uploader
3434
- S3 File Download
35+
- S3 List Buckets
36+
- S3 Create Bucket
37+
- S3 List Objects
3538
- SageMaker Chinese Toxicity Detector
3639
- SageMaker Text Rerank
3740
- SageMaker TTS

tools/s3_create_bucket.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""
2+
場所: tools/s3_create_bucket.py
3+
内容: 指定された名前とリージョンで S3 バケットを作成し、結果を返すツール。
4+
目的: ワークフロー内からバケットを安全に新規作成し、後続処理での利用を容易にする。
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from collections.abc import Generator
10+
from typing import Any
11+
12+
import boto3
13+
from botocore.exceptions import ClientError
14+
15+
from dify_plugin import Tool
16+
from dify_plugin.entities.tool import ToolInvokeMessage
17+
18+
try: # pragma: no cover - import path differs when packaged
19+
from my_aws_tools.provider.utils import (
20+
build_boto3_client_kwargs,
21+
resolve_aws_credentials,
22+
reset_clients_on_credential_change,
23+
)
24+
except ModuleNotFoundError: # pragma: no cover
25+
from provider.utils import (
26+
build_boto3_client_kwargs,
27+
resolve_aws_credentials,
28+
reset_clients_on_credential_change,
29+
)
30+
31+
32+
class S3CreateBucket(Tool):
33+
s3_client: Any = None
34+
35+
def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage, None, None]:
36+
"""S3 バケットを作成し、作成結果のサマリを返す。"""
37+
38+
try:
39+
credentials = resolve_aws_credentials(self, tool_parameters)
40+
if tool_parameters.get("aws_region"):
41+
credentials["aws_region"] = tool_parameters["aws_region"]
42+
43+
reset_clients_on_credential_change(self, credentials, ["s3_client"])
44+
if not self.s3_client:
45+
client_kwargs = build_boto3_client_kwargs(credentials)
46+
self.s3_client = boto3.client("s3", **client_kwargs)
47+
except Exception as exc: # pragma: no cover - boto3 init errors
48+
yield self.create_text_message(f"Failed to initialize AWS client: {exc}")
49+
return
50+
51+
bucket_name = (tool_parameters.get("bucket_name") or "").strip()
52+
if not bucket_name:
53+
yield self.create_text_message("bucket_name parameter is required")
54+
return
55+
56+
region = credentials.get("aws_region") or "us-east-1"
57+
acl = (tool_parameters.get("acl") or "").strip()
58+
59+
create_kwargs: dict[str, Any] = {"Bucket": bucket_name}
60+
if acl:
61+
create_kwargs["ACL"] = acl
62+
63+
if region != "us-east-1":
64+
create_kwargs["CreateBucketConfiguration"] = {"LocationConstraint": region}
65+
66+
try:
67+
response = self.s3_client.create_bucket(**create_kwargs)
68+
except ClientError as exc:
69+
error_message = exc.response.get("Error", {}).get("Message", str(exc))
70+
yield self.create_text_message(f"Failed to create bucket: {error_message}")
71+
return
72+
except Exception as exc: # pragma: no cover - unexpected errors
73+
yield self.create_text_message(f"Failed to create bucket: {exc}")
74+
return
75+
76+
location = response.get("Location")
77+
payload = {
78+
"bucket_name": bucket_name,
79+
"region": region,
80+
"acl": acl or "private",
81+
"location": location or f"/{bucket_name}",
82+
"s3_uri": f"s3://{bucket_name}/",
83+
}
84+
85+
yield self.create_json_message(payload)
86+
yield self.create_text_message(
87+
f"Bucket '{bucket_name}' created in {region}. Location: {payload['location']}"
88+
)

tools/s3_create_bucket.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
identity:
2+
name: s3_create_bucket
3+
author: r3-yamauchi
4+
label:
5+
en_US: AWS S3 Create Bucket
6+
zh_Hans: AWS S3 创建存储桶
7+
pt_BR: AWS S3 Criar Bucket
8+
ja_JP: AWS S3 バケット作成
9+
description:
10+
human:
11+
en_US: Create a new Amazon S3 bucket in the selected region.
12+
zh_Hans: 在指定的区域创建新的 Amazon S3 存储桶。
13+
pt_BR: Crie um novo bucket do Amazon S3 na região selecionada.
14+
ja_JP: 指定したリージョンに新しい Amazon S3 バケットを作成します。
15+
llm: Provision a fresh S3 bucket so that subsequent workflow nodes can store data there.
16+
parameters:
17+
- name: aws_access_key_id
18+
type: string
19+
required: false
20+
label:
21+
en_US: AWS Access Key ID
22+
ja_JP: AWS アクセスキー ID
23+
human_description:
24+
en_US: Override the provider Access Key ID for this request if needed.
25+
ja_JP: 必要に応じてプロバイダー設定を上書きする Access Key ID。
26+
form: form
27+
28+
- name: aws_secret_access_key
29+
type: string
30+
required: false
31+
label:
32+
en_US: AWS Secret Access Key
33+
ja_JP: AWS シークレットアクセスキー
34+
human_description:
35+
en_US: Override the provider Secret Access Key for this request if needed.
36+
ja_JP: 必要に応じてプロバイダー設定を上書きするシークレットキー。
37+
form: form
38+
39+
- name: aws_region
40+
type: string
41+
required: false
42+
label:
43+
en_US: AWS Region
44+
ja_JP: AWS リージョン
45+
human_description:
46+
en_US: Region where the new bucket will be created. Defaults to us-east-1.
47+
ja_JP: 新規バケットを作成するリージョン (未指定時は us-east-1)。
48+
form: form
49+
50+
- name: bucket_name
51+
type: string
52+
required: true
53+
label:
54+
en_US: Bucket name
55+
ja_JP: バケット名
56+
human_description:
57+
en_US: Globally unique S3 bucket name to create.
58+
ja_JP: 作成するグローバル一意な S3 バケット名。
59+
form: form
60+
61+
- name: acl
62+
type: string
63+
required: false
64+
label:
65+
en_US: ACL (optional)
66+
ja_JP: ACL (任意)
67+
human_description:
68+
en_US: Optional canned ACL such as private, public-read, or authenticated-read.
69+
ja_JP: private / public-read などの定義済み ACL を指定できます。省略時は private。
70+
form: form
71+
extra:
72+
python:
73+
source: tools/s3_create_bucket.py

0 commit comments

Comments
 (0)