Python interface to easily generate `serverless.yml`.
Project description
serverless-builder
Python interface to easily generate serverless.yml file.
Massive thanks goes to @dxd1 for his original idea and implementation.
Why
serverless.yml
easily can become a massive file with hundreds of lines, even if you have only a couple of services.
Modifying even semi advanced project can be difficult. Adding plugins and configuration for it, making sure your endless resources are configured correctly, making sure that you follow best practices. If you will multiple that by all microservices you have, it can be really painful.
How
serverless-builder
comes and tries to help you with those tasks.
- plugin management (with autoconfiguration)
- function factory (with some best practice hints (DLQ))
- autoconfiguration of some provider specific features like AWS X-Ray
- monitoring support (wip)
- easy resource manipulation with troposphere lib https://github.com/cloudtools/troposphere (but if you want you can use old good dict)
- easier IAM management with predefined permission sets
- built-in support for any serverless attributes
Example
from serverless.aws.functions.event_bridge import RetryPolicy
from serverless.aws.functions.http import HTTPFunction
from serverless import Service
from serverless.provider import AWSProvider
from serverless.aws.features import XRay
from serverless.aws.iam.dynamodb import DynamoDBReader
from serverless.plugins import ComposedVars, PythonRequirements, Prune
from troposphere.dynamodb import Table, AttributeDefinition, KeySchema
service = Service(
"service-name",
"some dummy service",
AWSProvider()
)
service.plugins.add(ComposedVars())
service.plugins.add(Prune())
service.plugins.add(PythonRequirements())
table = Table(
"TestTable",
BillingMode="PAY_PER_REQUEST",
AttributeDefinitions=[
AttributeDefinition(AttributeName="name", AttributeType="S")
],
KeySchema=[KeySchema(AttributeName="name", KeyType="HASH")]
)
service.enable(XRay())
service.provider.iam.apply(DynamoDBReader(table))
service.builder.function.generic("test", "description")
service.builder.function.http("test", "description", "/", HTTPFunction.POST)
# Multiple events with different paths and/or methods can be set up for the same handler
# This will add the same handler to all of these: POST /, POST /alias, PUT /, PUT /alias
service.builder.function.http("test", "description", ["/", "/alias"], ["POST", "PUT"], handler="shared.handler")
# Context with pre-defined setup
with service.preset(
layers=[{"Ref": "PythonRequirementsLambdaLayer"}],
handler="test.handlers.custom_handler.handle"
) as p:
p.http_get("test-list", "List all tests", "/")
p.http_get("test-get", "Get one test", "/{test_id}")
event_bridge_function = service.builder.function.event_bridge(
"event_bridge_function",
"sample event bridge function",
"epsy",
{"source": ["saas.external"]},
)
event_bridge_function.use_delivery_dlq(RetryPolicy(5, 300))
event_bridge_function.use_async_dlq()
service.resources.add(table)
service.render()
Project details
Release history Release notifications | RSS feed
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
Hashes for serverless_builder-1.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f27f998dfc8ef886f45cefea989a1e421e6a527f8788991a23bee6d515479f5a |
|
MD5 | 032a6fee530aa8f88f1f281cb7a5cbbd |
|
BLAKE2b-256 | 734f05d385f8e08ac077b36b38e1fbded16e6d9be483b1f1ef52f0736ecabff1 |