Skip to main content

Python interface to easily generate `serverless.yml`.

Project description

serverless-builder

PyPI Python License

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 release checkbox
    • Click Publish Release button.
  • Once published, it will trigger the release gh 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

serverless_builder-2.17.12.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

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

serverless_builder-2.17.12-py3-none-any.whl (56.6 kB view details)

Uploaded Python 3

File details

Details for the file serverless_builder-2.17.12.tar.gz.

File metadata

  • Download URL: serverless_builder-2.17.12.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for serverless_builder-2.17.12.tar.gz
Algorithm Hash digest
SHA256 94f817c85f363c893766ceea812e79871cd8495b1c443f07f22a9d05ac4d15c0
MD5 14490729b6e6cc68d17b18276fecfeb7
BLAKE2b-256 e2c3d31d84c1b643d86c9e0d0a33c14a6cde2096427ef4a7624f1cf309c4ea5f

See more details on using hashes here.

File details

Details for the file serverless_builder-2.17.12-py3-none-any.whl.

File metadata

File hashes

Hashes for serverless_builder-2.17.12-py3-none-any.whl
Algorithm Hash digest
SHA256 449f57bbcad02bd89b70829024da65c01a009f1058aa9293a8ca3fdfdbc3c3d1
MD5 8abd760b228b4032a558cff93084957c
BLAKE2b-256 ba4bfa8a251a33f34bbb10a1026a10c701ba4583513e92a1fcfd700fea8dee7d

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