展示 HN:Stelvio – 将 Python 部署到 AWS
Show HN: Stelvio – Ship Python to AWS

原始链接: https://stelvio.dev/

## Stelvio:简化的 AWS 部署 Stelvio 使用 Python 简化了部署和连接各种 AWS 服务。它允许轻松创建 **Lambda 函数**,这些函数可以由事件触发,例如 **S3 对象创建**(例如,`user-uploads` 存储桶通知 `process_upload.handler`)或通过 **cron 表达式** 调度(`hourly-cleanup`,`daily-report`)。 Stelvio 通过自动链接资源来简化权限管理——函数可以访问 **DynamoDB 表**(`users` 表链接到 `user-handler`),**S3 存储桶**(`reports` 存储桶链接到 `processor`),**SQS 队列**(`orders` 队列订阅 `processor`),和 **SNS 主题**(`alerts` 主题订阅 `notifier`)。 此外,Stelvio 促进了使用 **API Gateway** 构建 **REST API**(`payment-api` 将请求路由到 Lambda 函数),通过 **SES 发送电子邮件**(`support-email`),以及使用自动 SSL 管理 **自定义域名**。**Router** 资源将多个服务组合在一个域名下(例如,`/files` 到一个存储桶,`/api` 到一个 API)。 本质上,Stelvio 抽象了大量的 AWS 配置复杂性,从而实现快速应用程序开发。

## Stelvio:使用 Python 进行 AWS 基础设施即代码 一个名为 Stelvio (stelvio.dev) 的新工具允许用户使用 Python 代码定义和部署 AWS 基础设施。作者 Michal 在 Hacker News 上分享了该工具,Stelvio 目前专注于无服务器 AWS 服务,并计划扩展以支持 RDS、VPC 和容器等资源。 该工具引发了关于它在现有 IaC 领域中地位的讨论,并与 Pyinfra 进行了比较。反馈主要集中在命令行界面上——虽然作者最初选择了较短的“stlv”,但用户建议使用完整的“stelvio”名称以提高可读性和可搜索性,并可能为提高速度设置别名。 Michal 正在积极寻求反馈并解答有关该项目的问题,表明他愿意根据社区的意见来完善 Stelvio。
相关文章

原文

Deploy Python functions to AWS Lambda. Link to other resources for automatic permissions.

from stelvio.aws.function import Function
from stelvio.aws.s3 import Bucket

bucket = Bucket("reports")

# Link grants permissions automatically
Function(
    "processor",
    handler="functions/process.handler",
    links=[bucket],
)

Learn more about Lambda functions →

Schedule Lambda functions with cron expressions or rate intervals.

from stelvio.aws.cron import Cron

Cron(
    "hourly-cleanup",
    "rate(1 hour)",
    "functions/cleanup.handler",
)
Cron(
    "daily-report",
    "cron(0 9 * * ? *)",
    "functions/report.handler",
)

Learn more about Event scheduling →

Securely store any amount of data with AWS S3 Buckets.

from stelvio.aws.s3 import Bucket

# Create a bucket that triggers a function on new uploads
uploads = Bucket("user-uploads")
uploads.notify(
    "functions/process_upload.handler",
    events=["s3:ObjectCreated:*"],
)

Learn more about S3 Buckets →

Create DynamoDB tables and link them to functions for automatic permissions.

from stelvio.aws.dynamo_db import DynamoTable
from stelvio.aws.function import Function

table = DynamoTable(
    name="users",
    partition_key="user_id",
    sort_key="created_at",
)

Function(
    "user-handler",
    handler="functions/user.handler",
    links=[table],
)

Learn more about DynamoDB →

Decouple services with SQS queues and SNS topics.

from stelvio.aws.queue import Queue
from stelvio.aws.topic import Topic

orders = Queue("orders")
orders.subscribe(
    "processor",
    "functions/process_order.handler",
)

alerts = Topic("alerts")
alerts.subscribe(
    "notifier",
    "functions/send_alert.handler",
)

Learn more about SQS Queues & SNS Topics →

Send high-volume emails securely and reliably using Amazon SES.

from stelvio.aws.email import Email
from stelvio.aws.function import Function

mailer = Email(
    "support-email",
    "[email protected]",
)

Function(
    "sender",
    handler="functions/send.handler",
    links=[mailer],
)

Learn more about Email →

Define REST APIs and route requests to Lambda functions or other resources.

from stelvio.aws.apigateway import Api

api = Api(
    "payment-api",
    domain_name="api.example.com",
)

api.route("POST", "/charge", handler="functions/charge.post")
api.route("GET", "/history", handler="functions/history.get")

Learn more about API Gateway →

Connect your Stelvio resources to custom domains with automatic SSL certificates.

app = StelvioApp(
    "my-app",
    dns=CloudflareDns("your-cloudflare-zone-id")
    # other configurations...
)

...

api = Api(
    "payment-api",
    domain_name="api.example.com",
)

api.route("POST", "/charge", handler="functions/charge.post")
api.route("GET", "/history", handler="functions/history.get")

Learn more about Custom Domains →

Combine multiple Stelvio resources under the same custom domain using a Router.

domain_name = "example.com"

bucket = Bucket("static-files-bucket")

api = Api("my-api")
api.route("GET", "/api", "functions/hello.handler")

router = Router("router-example", custom_domain=domain_name)
router.route("/files", bucket)
router.route("/api", api)

Learn more about Router →

联系我们 contact @ memedata.com