Skip to content

docs: add gateway documentation #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/source/deploying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
44 changes: 40 additions & 4 deletions docs/source/gateway.rst
Original file line number Diff line number Diff line change
@@ -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
74 changes: 37 additions & 37 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
11 changes: 10 additions & 1 deletion scw_serverless/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
4 changes: 2 additions & 2 deletions scw_serverless/config/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://developers.scaleway.com/en/products/functions/api/#create-a-function>`_
"""

env: dict[str, str]
Expand Down