A nonebot2 plugin for managing AWS EC2, Lightsail, and Cost Explorer via commands.
Project description
nonebot_plugin_awsmgmt
一个用于 AWS 管理的 NoneBot2 插件。
使用方法
EC2
/ec2_start [target]/ec2_stop [target]/ec2_reboot [target]/ec2_status [target]
Target (目标):
tag:Key:Value: 例如tag:Project:MyProjectid:i-xxxx: 例如id:i-0fd0acc80b595ac71
如果未提供 target,插件将使用您在配置中设置的 aws_default_target_tag(如果已设置)。
Lightsail
/lightsail_list/lightsail_start <实例名称>/lightsail_stop <实例名称>
Cost Explorer (成本管理器)
/aws_cost today(今日成本)/aws_cost month(本月成本)/aws_cost month by_service(按服务划分的本月成本)
安装
-
安装插件
pip install nonebot-plugin-awsmgmt
-
在 NoneBot2 项目中加载插件
在
bot.py或pyproject.toml中添加nonebot_plugin_awsmgmt到插件列表。例如,在
pyproject.toml中:[tool.nonebot] plugins = ["nonebot_plugin_awsmgmt"]
-
配置 AWS 凭证
在您的 NoneBot2 项目的
.env文件中配置您的 AWS 访问密钥和秘密访问密钥:AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY AWS_REGION_NAME=your-aws-region # 例如: us-east-1
AWS 侧配置
为了使插件能够管理您的 AWS 资源,您需要在 AWS IAM 中创建一个具有适当权限的用户。
1. 创建 IAM Policy
创建一个新的 IAM Policy,并粘贴以下 JSON 内容。您可以根据需要修改此策略以限制权限。
Policy JSON (aws-policy.json):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeInstances",
"ec2:RebootInstances"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ec2:StartInstances",
"ec2:StopInstances"
],
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"StringEquals": {
"ec2:ResourceTag/ManagedBy": "nonebot-plugin-awsmgmt"
}
}
},
{
"Effect": "Allow",
"Action": [
"lightsail:GetInstances",
"lightsail:GetInstance",
"lightsail:StartInstance",
"lightsail:StopInstance"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ce:GetCostAndUsage"
],
"Resource": "*"
}
]
}
步骤:
- 登录 AWS 管理控制台。
- 导航到 IAM 服务。
- 在左侧导航栏中选择 Policies。
- 点击 Create policy。
- 选择 JSON 选项卡,并粘贴上述 Policy JSON 内容。
- 点击 Next: Tags,然后点击 Next: Review。
- 为策略命名(例如:
NoneBotAWSPolicy),并添加描述。 - 点击 Create policy。
2. 创建 IAM 用户并附加策略
创建一个新的 IAM 用户,并为其提供编程访问权限,然后附加您刚刚创建的策略。
步骤:
- 在 IAM 服务中,选择左侧导航栏中的 Users。
- 点击 Add user。
- 输入用户名(例如:
nonebot-aws-user)。 - 在 Select AWS access type 部分,勾选 Programmatic access。
- 点击 Next: Permissions。
- 选择 Attach existing policies directly。
- 搜索并选择您刚刚创建的策略(例如:
NoneBotAWSPolicy)。 - 点击 Next: Tags,然后点击 Next: Review。
- 点击 Create user。
- 重要: 记录下生成的 Access key ID 和 Secret access key。这些将用于配置 NoneBot2 插件。这些凭证只显示一次,请务必妥善保管。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_plugin_awsmgmt-0.1.3.tar.gz.
File metadata
- Download URL: nonebot_plugin_awsmgmt-0.1.3.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30f9846bdc342218af9aa03ab5f5f361e7c059ba1e60bf507fc2953d35c0d8c9
|
|
| MD5 |
d4249245422b671fa72a2a0f3c113ae4
|
|
| BLAKE2b-256 |
9f7417a8ef663d102c1fcc42c7993daac15056f61413d478a25707b7f3769496
|
File details
Details for the file nonebot_plugin_awsmgmt-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nonebot_plugin_awsmgmt-0.1.3-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44824f207460d361d964d136a3116a84a4b8e82beb8fbe0a259cdf71496f8663
|
|
| MD5 |
f1bc0f041028d68037e118d01c3c7a00
|
|
| BLAKE2b-256 |
4f6a62091418639b231e8336f5818bef675227eaab2af24650ca95b255e3fc14
|