Skip to main content

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:MyProject
  • id: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 (按服务划分的本月成本)

安装

  1. 安装插件

    pip install nonebot-plugin-awsmgmt
    
  2. 在 NoneBot2 项目中加载插件

    bot.pypyproject.toml 中添加 nonebot_plugin_awsmgmt 到插件列表。

    例如,在 pyproject.toml 中:

    [tool.nonebot]
    plugins = ["nonebot_plugin_awsmgmt"]
    
  3. 配置 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": "*"
        }
    ]
}

步骤:

  1. 登录 AWS 管理控制台。
  2. 导航到 IAM 服务。
  3. 在左侧导航栏中选择 Policies
  4. 点击 Create policy
  5. 选择 JSON 选项卡,并粘贴上述 Policy JSON 内容。
  6. 点击 Next: Tags,然后点击 Next: Review
  7. 为策略命名(例如:NoneBotAWSPolicy),并添加描述。
  8. 点击 Create policy

2. 创建 IAM 用户并附加策略

创建一个新的 IAM 用户,并为其提供编程访问权限,然后附加您刚刚创建的策略。

步骤:

  1. 在 IAM 服务中,选择左侧导航栏中的 Users
  2. 点击 Add user
  3. 输入用户名(例如:nonebot-aws-user)。
  4. Select AWS access type 部分,勾选 Programmatic access
  5. 点击 Next: Permissions
  6. 选择 Attach existing policies directly
  7. 搜索并选择您刚刚创建的策略(例如:NoneBotAWSPolicy)。
  8. 点击 Next: Tags,然后点击 Next: Review
  9. 点击 Create user
  10. 重要: 记录下生成的 Access key IDSecret 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

nonebot_plugin_awsmgmt-0.1.3.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nonebot_plugin_awsmgmt-0.1.3-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

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

Hashes for nonebot_plugin_awsmgmt-0.1.3.tar.gz
Algorithm Hash digest
SHA256 30f9846bdc342218af9aa03ab5f5f361e7c059ba1e60bf507fc2953d35c0d8c9
MD5 d4249245422b671fa72a2a0f3c113ae4
BLAKE2b-256 9f7417a8ef663d102c1fcc42c7993daac15056f61413d478a25707b7f3769496

See more details on using hashes here.

File details

Details for the file nonebot_plugin_awsmgmt-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for nonebot_plugin_awsmgmt-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 44824f207460d361d964d136a3116a84a4b8e82beb8fbe0a259cdf71496f8663
MD5 f1bc0f041028d68037e118d01c3c7a00
BLAKE2b-256 4f6a62091418639b231e8336f5818bef675227eaab2af24650ca95b255e3fc14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page