Python interface to easily generate `serverless.yml`.
Project description
serverless-builder
Python interface to easily generate serverless.yml file.
To read more about features, visit 📜 our documentation.
Installation
pip install serverless-builder
Features
- plugin management with autoconfiguration
- function factory with some best practice hints
- autoconfiguration of some provider specific features like AWS X-Ray
- easy resource manipulation with troposphere lib (but if you want you can use old good dict)
- easier IAM management with predefined permission sets
- built-in support for any serverless attributes
- integration with aws lambda powertools
Example of use
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()
New version release process
-
Update the version in pyproject.toml
# increase the version number as per SemVer standards version = "2.13.17" -
Once ready to publish, create a new github release
- its a good practice to match the tag with the version number as in pyproject.toml
- Select
set as latest releasecheckbox - Click
Publish Releasebutton.
-
Once published, it will trigger the
releasegh wf and publish the latest package to PyPi.
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
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 serverless_builder-2.17.4.tar.gz.
File metadata
- Download URL: serverless_builder-2.17.4.tar.gz
- Upload date:
- Size: 31.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4fd6b9942edfc105348d5269cffd56f1574406879ae237508d031d9521a723b
|
|
| MD5 |
be820b7f90fe10e6a269671796b85c51
|
|
| BLAKE2b-256 |
9abead27dbc0b29bb5ffab44b48a07f2e8f6f878f8530ebf7a9985815f3628a5
|
File details
Details for the file serverless_builder-2.17.4-py3-none-any.whl.
File metadata
- Download URL: serverless_builder-2.17.4-py3-none-any.whl
- Upload date:
- Size: 55.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c273be24479c31b5d4054b276a6092ac2e909596ed54c38aeb1e7f3d23bf623
|
|
| MD5 |
775b2a0fb4293ce283a8c57df2433f24
|
|
| BLAKE2b-256 |
3f0127d02344993a1678d55d9f2f88dac8af92f4dbdcafa4d4f23ac2a5022614
|