diff --git a/docs/source/configuring.rst b/docs/source/configuring.rst index ee102df..3a3f5cd 100644 --- a/docs/source/configuring.rst +++ b/docs/source/configuring.rst @@ -24,12 +24,12 @@ When deploying, the `scw-serverless` CLI will look for a Serverless instance in }) .. autoclass:: scw_serverless.app.Serverless - :members: func + :members: func, get, post, put Functions --------- -To configure your serverless functions, you can provide keyword arguments to the decorators. The Function name that will appear in Scaleway console will be the name of your function's handler. +To configure your serverless functions, you can provide keyword arguments to the decorators. The Function name that will appear in the Scaleway console will be the name of your function's handler. .. autoclass:: scw_serverless.config.function.FunctionKwargs diff --git a/docs/source/deploying.rst b/docs/source/deploying.rst index 829e2df..0c7df98 100644 --- a/docs/source/deploying.rst +++ b/docs/source/deploying.rst @@ -18,7 +18,7 @@ Generate -------- Generators will generate configuration files to use with other deployment tools. -Currently, you can generate either a `serverless` or `terraform` configuration file. This can useful to integrate with your existing tooling. +Currently, you can generate either a `serverless` or `terraform` configuration file. This can be useful to integrate with your existing tooling. Config file generation is done with the `generate` command: diff --git a/docs/source/gateway.rst b/docs/source/gateway.rst index 1a85742..b5ac0c5 100644 --- a/docs/source/gateway.rst +++ b/docs/source/gateway.rst @@ -1,9 +1,45 @@ API Gateway =========== -.. warning:: Not yet implemented. +The framework provides support for routed functions via a Gateway container that can be deployed separately. +For more information, please consult the documentation on the `Serverless Gateway repository`_ -Routed functions -^^^^^^^^^^^^^^^^ +Quickstart +^^^^^^^^^^ -.. autodocs:: scw_serverless.app.Serverless.func +* Write your routed function + +.. code-block:: python + + # In app.py + + app = Serverless("example") + + app.get("/hello-gateway", memory_limit= 256) + def handler(event, context): + return {"body": "Hello from Gateway!"} + +* Clone the `Serverless Gateway repository`_ +* Follow the steps in README to deploy your API Gateway +* Create an API token for the Gateway. In the gateway repository, you can use a make command: + +.. code-block:: console + + make generate-token + export TOKEN=$(make get-token) + export GATEWAY_HOST=$(make gateway-host) + +* Finally, use `scw-serverless` to deploy your function and set up the route on your Gateway: + +.. code-block:: console + + scw-serverless deploy app.py --gateway-url https://${GATEWAY_HOST} --gateway-api-key ${TOKEN} + +* You can now call your function via your Gateway! + +.. code-block:: console + + $ curl https://${GATEWAY_HOST}/hello-gateway + > Hello from Gateway! + +.. _Serverless Gateway Repository: https://github.com/scaleway/serverless-gateway diff --git a/poetry.lock b/poetry.lock index c601b49..18c316e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -14,14 +14,14 @@ files = [ [[package]] name = "astroid" -version = "2.15.2" +version = "2.15.3" description = "An abstract syntax tree for Python with inference support." category = "dev" optional = false python-versions = ">=3.7.2" files = [ - {file = "astroid-2.15.2-py3-none-any.whl", hash = "sha256:dea89d9f99f491c66ac9c04ebddf91e4acf8bd711722175fe6245c0725cc19bb"}, - {file = "astroid-2.15.2.tar.gz", hash = "sha256:6e61b85c891ec53b07471aec5878f4ac6446a41e590ede0f2ce095f39f7d49dd"}, + {file = "astroid-2.15.3-py3-none-any.whl", hash = "sha256:f11e74658da0f2a14a8d19776a8647900870a63de71db83713a8e77a6af52662"}, + {file = "astroid-2.15.3.tar.gz", hash = "sha256:44224ad27c54d770233751315fa7f74c46fa3ee0fab7beef1065f99f09897efe"}, ] [package.dependencies] @@ -46,18 +46,18 @@ files = [ [[package]] name = "boto3" -version = "1.26.113" +version = "1.26.114" description = "The AWS SDK for Python" category = "dev" optional = false python-versions = ">= 3.7" files = [ - {file = "boto3-1.26.113-py3-none-any.whl", hash = "sha256:631db554cf9d98a2d29c0533a7020cf967b6800437be36e4335e654a480dfcdf"}, - {file = "boto3-1.26.113.tar.gz", hash = "sha256:0de50b90e14e1dc3037d302f45edbf7b342ba2540f464e9ce60bad12651f02e1"}, + {file = "boto3-1.26.114-py3-none-any.whl", hash = "sha256:e32977256470b4de3a25a43acdf6c8e6375e762656ace292ad2ceba446203615"}, + {file = "boto3-1.26.114.tar.gz", hash = "sha256:b10324d452fe677d6e1005b650ae11158cf21310e0c0062b00d184b352f4196b"}, ] [package.dependencies] -botocore = ">=1.29.113,<1.30.0" +botocore = ">=1.29.114,<1.30.0" jmespath = ">=0.7.1,<2.0.0" s3transfer = ">=0.6.0,<0.7.0" @@ -66,14 +66,14 @@ crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] [[package]] name = "botocore" -version = "1.29.113" +version = "1.29.114" description = "Low-level, data-driven core of boto 3." category = "dev" optional = false python-versions = ">= 3.7" files = [ - {file = "botocore-1.29.113-py3-none-any.whl", hash = "sha256:d927c1fbf5f5caf7937b5f53eb158c708bcbe3b6aa6d46e1fbd353241f21b5b0"}, - {file = "botocore-1.29.113.tar.gz", hash = "sha256:acfee1faaa3ef2a6931fe574c092f596afb48f3c49e054aec7cfa8494227c031"}, + {file = "botocore-1.29.114-py3-none-any.whl", hash = "sha256:dd61f445eb53fe906dbde86405915cce61ffa13824a1bb7b826bfc7869a3e628"}, + {file = "botocore-1.29.114.tar.gz", hash = "sha256:aeacb03303d6babb0490247158647346d27900fcf89bfb9713db41f1ce1cc93f"}, ] [package.dependencies] @@ -291,18 +291,18 @@ testing = ["pre-commit"] [[package]] name = "filelock" -version = "3.10.7" +version = "3.11.0" description = "A platform independent file lock." category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "filelock-3.10.7-py3-none-any.whl", hash = "sha256:bde48477b15fde2c7e5a0713cbe72721cb5a5ad32ee0b8f419907960b9d75536"}, - {file = "filelock-3.10.7.tar.gz", hash = "sha256:892be14aa8efc01673b5ed6589dbccb95f9a8596f0507e232626155495c18105"}, + {file = "filelock-3.11.0-py3-none-any.whl", hash = "sha256:f08a52314748335c6460fc8fe40cd5638b85001225db78c2aa01c8c0db83b318"}, + {file = "filelock-3.11.0.tar.gz", hash = "sha256:3618c0da67adcc0506b015fd11ef7faf1b493f0b40d87728e19986b536890c37"}, ] [package.extras] -docs = ["furo (>=2022.12.7)", "sphinx (>=6.1.3)", "sphinx-autodoc-typehints (>=1.22,!=1.23.4)"] +docs = ["furo (>=2023.3.27)", "sphinx (>=6.1.3)", "sphinx-autodoc-typehints (>=1.22,!=1.23.4)"] testing = ["covdefaults (>=2.3)", "coverage (>=7.2.2)", "diff-cover (>=7.5)", "pytest (>=7.2.2)", "pytest-cov (>=4)", "pytest-mock (>=3.10)", "pytest-timeout (>=2.1)"] [[package]] @@ -346,14 +346,14 @@ files = [ [[package]] name = "importlib-metadata" -version = "6.1.0" +version = "6.4.1" description = "Read metadata from Python packages" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "importlib_metadata-6.1.0-py3-none-any.whl", hash = "sha256:ff80f3b5394912eb1b108fcfd444dc78b7f1f3e16b16188054bd01cb9cb86f09"}, - {file = "importlib_metadata-6.1.0.tar.gz", hash = "sha256:43ce9281e097583d758c2c708c4376371261a02c34682491a8e98352365aad20"}, + {file = "importlib_metadata-6.4.1-py3-none-any.whl", hash = "sha256:63ace321e24167d12fbb176b6015f4dbe06868c54a2af4f15849586afb9027fd"}, + {file = "importlib_metadata-6.4.1.tar.gz", hash = "sha256:eb1a7933041f0f85c94cd130258df3fb0dec060ad8c1c9318892ef4192c47ce1"}, ] [package.dependencies] @@ -643,14 +643,14 @@ setuptools = "*" [[package]] name = "packaging" -version = "23.0" +version = "23.1" description = "Core utilities for Python packages" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "packaging-23.0-py3-none-any.whl", hash = "sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2"}, - {file = "packaging-23.0.tar.gz", hash = "sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97"}, + {file = "packaging-23.1-py3-none-any.whl", hash = "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61"}, + {file = "packaging-23.1.tar.gz", hash = "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f"}, ] [[package]] @@ -706,14 +706,14 @@ virtualenv = ">=20.10.0" [[package]] name = "pygments" -version = "2.14.0" +version = "2.15.0" description = "Pygments is a syntax highlighting package written in Python." category = "dev" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "Pygments-2.14.0-py3-none-any.whl", hash = "sha256:fa7bd7bd2771287c0de303af8bfdfc731f51bd2c6a47ab69d117138893b82717"}, - {file = "Pygments-2.14.0.tar.gz", hash = "sha256:b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297"}, + {file = "Pygments-2.15.0-py3-none-any.whl", hash = "sha256:77a3299119af881904cd5ecd1ac6a66214b6e9bed1f2db16993b54adede64094"}, + {file = "Pygments-2.15.0.tar.gz", hash = "sha256:f7e36cffc4c517fbc252861b9a6e4644ca0e5abadf9a113c72d1358ad09b9500"}, ] [package.extras] @@ -766,14 +766,14 @@ tomli = {version = ">=2.0.1,<3.0.0", markers = "python_version < \"3.11\""} [[package]] name = "pytest" -version = "7.3.0" +version = "7.3.1" description = "pytest: simple powerful testing with Python" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "pytest-7.3.0-py3-none-any.whl", hash = "sha256:933051fa1bfbd38a21e73c3960cebdad4cf59483ddba7696c48509727e17f201"}, - {file = "pytest-7.3.0.tar.gz", hash = "sha256:58ecc27ebf0ea643ebfdf7fb1249335da761a00c9f955bcd922349bcb68ee57d"}, + {file = "pytest-7.3.1-py3-none-any.whl", hash = "sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362"}, + {file = "pytest-7.3.1.tar.gz", hash = "sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3"}, ] [package.dependencies] @@ -1009,27 +1009,27 @@ files = [ [[package]] name = "sphinx" -version = "5.3.0" +version = "6.1.3" description = "Python documentation generator" category = "dev" optional = false -python-versions = ">=3.6" +python-versions = ">=3.8" files = [ - {file = "Sphinx-5.3.0.tar.gz", hash = "sha256:51026de0a9ff9fc13c05d74913ad66047e104f56a129ff73e174eb5c3ee794b5"}, - {file = "sphinx-5.3.0-py3-none-any.whl", hash = "sha256:060ca5c9f7ba57a08a1219e547b269fadf125ae25b06b9fa7f66768efb652d6d"}, + {file = "Sphinx-6.1.3.tar.gz", hash = "sha256:0dac3b698538ffef41716cf97ba26c1c7788dba73ce6f150c1ff5b4720786dd2"}, + {file = "sphinx-6.1.3-py3-none-any.whl", hash = "sha256:807d1cb3d6be87eb78a381c3e70ebd8d346b9a25f3753e9947e866b2786865fc"}, ] [package.dependencies] alabaster = ">=0.7,<0.8" babel = ">=2.9" colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} -docutils = ">=0.14,<0.20" +docutils = ">=0.18,<0.20" imagesize = ">=1.3" importlib-metadata = {version = ">=4.8", markers = "python_version < \"3.10\""} Jinja2 = ">=3.0" packaging = ">=21.0" -Pygments = ">=2.12" -requests = ">=2.5.0" +Pygments = ">=2.13" +requests = ">=2.25.0" snowballstemmer = ">=2.0" sphinxcontrib-applehelp = "*" sphinxcontrib-devhelp = "*" @@ -1040,8 +1040,8 @@ sphinxcontrib-serializinghtml = ">=1.1.5" [package.extras] docs = ["sphinxcontrib-websupport"] -lint = ["docutils-stubs", "flake8 (>=3.5.0)", "flake8-bugbear", "flake8-comprehensions", "flake8-simplify", "isort", "mypy (>=0.981)", "sphinx-lint", "types-requests", "types-typed-ast"] -test = ["cython", "html5lib", "pytest (>=4.6)", "typed_ast"] +lint = ["docutils-stubs", "flake8 (>=3.5.0)", "flake8-simplify", "isort", "mypy (>=0.990)", "ruff", "sphinx-lint", "types-requests"] +test = ["cython", "html5lib", "pytest (>=4.6)"] [[package]] name = "sphinx-rtd-theme" @@ -1363,4 +1363,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "0ce84cc3bfcaa0ff97ac81027b9a616973ffbd18776f2b7da8a4d74c78b7f387" +content-hash = "8b4c72e666392ac10e6ad87f8fcc119970fd26be51eae1dfef5479f0a2405a91" diff --git a/pyproject.toml b/pyproject.toml index 798f563..15086d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,9 +57,9 @@ boto3 = "^1.26.97" optional = true [tool.poetry.group.doc.dependencies] -myst_parser = ">=0.18.1,<1.1.0" -sphinx = "^5.3.0" -sphinx_rtd_theme = "^1.1.1" +myst_parser = "^1.0.0" +sphinx = "^6.1.0" +sphinx_rtd_theme = "^1.2.0" [tool.pytest.ini_options] filterwarnings = [ diff --git a/scw_serverless/app.py b/scw_serverless/app.py index 4a6e9de..1db72e7 100644 --- a/scw_serverless/app.py +++ b/scw_serverless/app.py @@ -104,6 +104,8 @@ def get(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable: .. note:: Requires an API gateway + + For more information, please consult the :doc:`gateway` page. """ kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.GET]} return self.func(**kwargs) @@ -114,8 +116,9 @@ def post(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable: :param url: relative url to trigger the function .. note:: - Requires an API gateway + + For more information, please consult the :doc:`gateway` page. """ kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.POST]} return self.func(**kwargs) @@ -128,6 +131,8 @@ def put(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable: .. note:: Requires an API gateway + + For more information, please consult the :doc:`gateway` page. """ kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.PUT]} return self.func(**kwargs) @@ -140,6 +145,8 @@ def delete(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable: .. note:: Requires an API gateway + + For more information, please consult the :doc:`gateway` page. """ kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.DELETE]} return self.func(**kwargs) @@ -152,6 +159,8 @@ def patch(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable: .. note:: Requires an API gateway + + For more information, please consult the :doc:`gateway` page. """ kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.PATCH]} return self.func(**kwargs) diff --git a/scw_serverless/config/function.py b/scw_serverless/config/function.py index 7618817..caaea70 100644 --- a/scw_serverless/config/function.py +++ b/scw_serverless/config/function.py @@ -46,8 +46,8 @@ class FunctionKwargs(TypedDict, total=False): .. seealso:: - Scaleway Developers Documentation - https://developers.scaleway.com/en/products/functions/api/#create-a-function + `Scaleway Developers Documentation + `_ """ env: dict[str, str]