From 86793a93920e40c5fe04c8858688bb94fb87b467 Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Fri, 31 Mar 2023 18:13:31 +0200 Subject: [PATCH 01/18] feat: python serverless api with serverless gateway --- README.md | 2 ++ functions/serverless-gateway-python/app.py | 15 +++++++++++++++ .../serverless-gateway-python/requirements.txt | 1 + .../scripts/add_function_to_gateway.sh | 4 ++++ .../scripts/delete_function_from_gateway.sh | 4 ++++ .../scripts/list_gateway_endpoints.sh | 1 + 6 files changed, 27 insertions(+) create mode 100644 functions/serverless-gateway-python/app.py create mode 100644 functions/serverless-gateway-python/requirements.txt create mode 100644 functions/serverless-gateway-python/scripts/add_function_to_gateway.sh create mode 100644 functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh create mode 100644 functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh diff --git a/README.md b/README.md index 9603ba6..cc0c065 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Table of Contents: | **[PostgreSQL Python](functions/postgre-sql-python/README.md)**
A Python function to perform a query on a PostgreSQL managed database. | python310 | [Serverless Framework] | | **[Terraform Python](functions/terraform-python-example/README.md)**
A Python function deployed with Terraform. | python310 | [Terraform] | | **[Typescript with Node runtime](functions/typescript-with-node/README.md)**
A Typescript function using Node runtime. | node18 | [Serverless Framework] | +| **[Serverless Gateway Python Example](functions/serverless-gateway-python/README.md)**
A Python serverless API using Serverless Gateway. | node18 | [Serverless Framework] | ### 📦 Containers @@ -60,6 +61,7 @@ Table of Contents: | Example | Services | Language | Deployment | |-------------------------------------------------------------------------------------------------------------------------------------------|-------------|----------|------------------------| | **[Kong API Gateway](projects/kong-api-gateway/README.md)**
Deploying a Kong Gateway on containers to provide routing to functions. | CaaS & FaaS | Python | [Serverless Framework] | +| **[Serverless Gateway](https://github.com/scaleway/serverless-gateway)**
Our serverless gateway for functions and containers. | API Gateway | Python | CaaS | | **[Monitoring Glaciers](projects/blogpost-glacier/README.md)**
A project to monitor glaciers and the impact of global warming. | S3 & RDB | Golang | [Serverless Framework] | [Serverless Framework]: https://github.com/scaleway/serverless-scaleway-functions diff --git a/functions/serverless-gateway-python/app.py b/functions/serverless-gateway-python/app.py new file mode 100644 index 0000000..b829556 --- /dev/null +++ b/functions/serverless-gateway-python/app.py @@ -0,0 +1,15 @@ +from scw_serverless import Serverless + +app = Serverless("serverless-api") + +@app.func() +def func_a(_event, _context): + return "Hello from function A" + +@app.func() +def func_b(_event, _context): + return "Hello from function B" + +@app.func() +def func_c(_event, _context): + return "Hello from function C" \ No newline at end of file diff --git a/functions/serverless-gateway-python/requirements.txt b/functions/serverless-gateway-python/requirements.txt new file mode 100644 index 0000000..e69e888 --- /dev/null +++ b/functions/serverless-gateway-python/requirements.txt @@ -0,0 +1 @@ +scw-serverless~=0.0.4 \ No newline at end of file diff --git a/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh b/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh new file mode 100644 index 0000000..4d4348c --- /dev/null +++ b/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh @@ -0,0 +1,4 @@ +curl -X POST http://${GATEWAY_URL}/scw \ + -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ + -H 'Content-Type: application/json' \ + -d '{"target":"$1","relative_url":"/$2"}' \ No newline at end of file diff --git a/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh b/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh new file mode 100644 index 0000000..4d4348c --- /dev/null +++ b/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh @@ -0,0 +1,4 @@ +curl -X POST http://${GATEWAY_URL}/scw \ + -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ + -H 'Content-Type: application/json' \ + -d '{"target":"$1","relative_url":"/$2"}' \ No newline at end of file diff --git a/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh b/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh new file mode 100644 index 0000000..a8f0776 --- /dev/null +++ b/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh @@ -0,0 +1 @@ +curl http://${GATEWAY_URL}/scw -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ No newline at end of file From b74ffc6d04211126c10a2ad5bfaad5e2349b6e79 Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Mon, 3 Apr 2023 09:30:01 +0200 Subject: [PATCH 02/18] docs: add example readme --- functions/serverless-gateway-python/README.md | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 functions/serverless-gateway-python/README.md diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md new file mode 100644 index 0000000..652d5bb --- /dev/null +++ b/functions/serverless-gateway-python/README.md @@ -0,0 +1,55 @@ +# Using Serverless Gateway and Serverless APIs + +This example shows how to serve a Serverless API composed of many functions through our serverless gateway. + +## Requirements + +This example uses: +* [Python API Framework](https://github.com/scaleway/serverless-api-project) to deploy the functions. +* [Serverless Gateway](https://github.com/scaleway/serverless-gateway) to deploy the a serverless gateway as a container. + +## Gateway set-up + +Deploy the serverless gateway as a container following the Serverless Gateway project instructions. + +Make sure to export your gateway base URL (`GATEWAY_URL`) and an authentication token (`$GATEWAY_TOKEN`) + +## Running + +### Deploy your serverless API + +Deploy your functions using: + +``` +pip install -r requirements.txt +scw_serverless deploy app.py +``` + +### Add your functions to gateway endpoints + +You can add your function to the gateway with a chosen relative path using: +``` +sh scripts/add_function_to_gateway.sh http:// / +``` + +### Verify that your function is added to the gateway: + +You can use: +``` +sh list_gateway_endpoints.sh +``` + +### Call your functions through gateway + +You can use: +``` +curl scripts/http://${GATEWAY_URL}/ +``` + +### Delete your function through gateway + +You can use: +``` +sh scripts/delete_function_to_gateway.sh http:// / +``` + From 95d84d14c8e2fd5043b82089a4dbe1ffabf8bedf Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:56:09 +0200 Subject: [PATCH 03/18] fix: impement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc0c065..b556d73 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Table of Contents: | **[PostgreSQL Python](functions/postgre-sql-python/README.md)**
A Python function to perform a query on a PostgreSQL managed database. | python310 | [Serverless Framework] | | **[Terraform Python](functions/terraform-python-example/README.md)**
A Python function deployed with Terraform. | python310 | [Terraform] | | **[Typescript with Node runtime](functions/typescript-with-node/README.md)**
A Typescript function using Node runtime. | node18 | [Serverless Framework] | -| **[Serverless Gateway Python Example](functions/serverless-gateway-python/README.md)**
A Python serverless API using Serverless Gateway. | node18 | [Serverless Framework] | +| **[Serverless Gateway Python Example](functions/serverless-gateway-python/README.md)**
A Python serverless API using Serverless Gateway. | python310 | [Python API Framework] | ### 📦 Containers From 220c56e9ad248b8b2164c126b7f37f8b5671dff0 Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:56:39 +0200 Subject: [PATCH 04/18] fix: impement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- functions/serverless-gateway-python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 652d5bb..7bd550d 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -12,7 +12,7 @@ This example uses: Deploy the serverless gateway as a container following the Serverless Gateway project instructions. -Make sure to export your gateway base URL (`GATEWAY_URL`) and an authentication token (`$GATEWAY_TOKEN`) +Make sure to export your gateway base URL (`GATEWAY_URL`) and an authentication token (`GATEWAY_TOKEN`) ## Running From 557cd8d96d711a29f90138fe1fc0230664a74a8a Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:56:54 +0200 Subject: [PATCH 05/18] fix: impement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- functions/serverless-gateway-python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 7bd550d..39ffc40 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -25,7 +25,7 @@ pip install -r requirements.txt scw_serverless deploy app.py ``` -### Add your functions to gateway endpoints +### Add routes to your functions in the gateway You can add your function to the gateway with a chosen relative path using: ``` From a8ac65d65db5555a0eff6ebc5e24d45498ca3698 Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:57:31 +0200 Subject: [PATCH 06/18] fix: implement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- functions/serverless-gateway-python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 39ffc40..013a9e8 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -32,7 +32,7 @@ You can add your function to the gateway with a chosen relative path using: sh scripts/add_function_to_gateway.sh http:// / ``` -### Verify that your function is added to the gateway: +### Check your route has been added You can use: ``` From cc566f1043fbb921a7b6d30877c8e8b5e85c4ad6 Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:57:46 +0200 Subject: [PATCH 07/18] fix: implement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- functions/serverless-gateway-python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 013a9e8..19ec846 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -39,7 +39,7 @@ You can use: sh list_gateway_endpoints.sh ``` -### Call your functions through gateway +### Call your functions via the routes You can use: ``` From f7e986c80c7edf7eba7547a38eb50b5b3995a94a Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:58:03 +0200 Subject: [PATCH 08/18] fix: implement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- functions/serverless-gateway-python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 19ec846..7cd315b 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -46,7 +46,7 @@ You can use: curl scripts/http://${GATEWAY_URL}/ ``` -### Delete your function through gateway +### Delete your routes You can use: ``` From 480bb667241a2d308c74900e856f77d8a706c426 Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:59:07 +0200 Subject: [PATCH 09/18] fix: implement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b556d73..65816f6 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Table of Contents: | Example | Services | Language | Deployment | |-------------------------------------------------------------------------------------------------------------------------------------------|-------------|----------|------------------------| | **[Kong API Gateway](projects/kong-api-gateway/README.md)**
Deploying a Kong Gateway on containers to provide routing to functions. | CaaS & FaaS | Python | [Serverless Framework] | -| **[Serverless Gateway](https://github.com/scaleway/serverless-gateway)**
Our serverless gateway for functions and containers. | API Gateway | Python | CaaS | +| **[Serverless Gateway](https://github.com/scaleway/serverless-gateway)**
Our serverless gateway for functions and containers. | API Gateway | Python | [Python API Framework] | | **[Monitoring Glaciers](projects/blogpost-glacier/README.md)**
A project to monitor glaciers and the impact of global warming. | S3 & RDB | Golang | [Serverless Framework] | [Serverless Framework]: https://github.com/scaleway/serverless-scaleway-functions From f61f73bfba8c71dddbc39b9201cf76b19800a239 Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:59:30 +0200 Subject: [PATCH 10/18] fix: implement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- functions/serverless-gateway-python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 7cd315b..c892e13 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -6,7 +6,7 @@ This example shows how to serve a Serverless API composed of many functions thro This example uses: * [Python API Framework](https://github.com/scaleway/serverless-api-project) to deploy the functions. -* [Serverless Gateway](https://github.com/scaleway/serverless-gateway) to deploy the a serverless gateway as a container. +* [Serverless Gateway](https://github.com/scaleway/serverless-gateway) to deploy a serverless gateway container. ## Gateway set-up From 8883f8ba592e92941334d13093e70bb0515ba858 Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Mon, 3 Apr 2023 13:07:11 +0200 Subject: [PATCH 11/18] chore: update script start --- .../scripts/add_function_to_gateway.sh | 3 +++ .../scripts/delete_function_from_gateway.sh | 3 +++ .../scripts/list_gateway_endpoints.sh | 3 +++ 3 files changed, 9 insertions(+) diff --git a/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh b/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh index 4d4348c..6d13a7f 100644 --- a/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh +++ b/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh @@ -1,3 +1,6 @@ +#!/bin/bash +set -e + curl -X POST http://${GATEWAY_URL}/scw \ -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ -H 'Content-Type: application/json' \ diff --git a/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh b/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh index 4d4348c..6d13a7f 100644 --- a/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh +++ b/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh @@ -1,3 +1,6 @@ +#!/bin/bash +set -e + curl -X POST http://${GATEWAY_URL}/scw \ -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ -H 'Content-Type: application/json' \ diff --git a/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh b/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh index a8f0776..843bd46 100644 --- a/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh +++ b/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh @@ -1 +1,4 @@ +#!/bin/bash +set -e + curl http://${GATEWAY_URL}/scw -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ No newline at end of file From d0de2d337ec4afaacd26a0c9d91245d42c728736 Mon Sep 17 00:00:00 2001 From: Reda Noureddine <58738453+redanrd@users.noreply.github.com> Date: Mon, 3 Apr 2023 13:27:06 +0200 Subject: [PATCH 12/18] fix: implement review Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --- functions/serverless-gateway-python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index c892e13..b4e55d0 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -29,7 +29,7 @@ scw_serverless deploy app.py You can add your function to the gateway with a chosen relative path using: ``` -sh scripts/add_function_to_gateway.sh http:// / +./scripts/add_function_to_gateway.sh http:// / ``` ### Check your route has been added From aa8ac02fddfc64c9645dd8f237a9e4407c6917df Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Mon, 3 Apr 2023 13:33:11 +0200 Subject: [PATCH 13/18] docs: call scripts as executables in readme --- functions/serverless-gateway-python/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index b4e55d0..4f699a6 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -36,20 +36,20 @@ You can add your function to the gateway with a chosen relative path using: You can use: ``` -sh list_gateway_endpoints.sh +./list_gateway_endpoints.sh ``` ### Call your functions via the routes You can use: ``` -curl scripts/http://${GATEWAY_URL}/ +curl http://${GATEWAY_URL}/ ``` ### Delete your routes You can use: ``` -sh scripts/delete_function_to_gateway.sh http:// / +./scripts/delete_function_to_gateway.sh http:// / ``` From eec834bb8610eb0258d6977b5aced4251e6bb33e Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Mon, 3 Apr 2023 13:43:56 +0200 Subject: [PATCH 14/18] fix: update relative path in scripts --- .../scripts/add_function_to_gateway.sh | 2 +- .../scripts/delete_function_from_gateway.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh b/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh index 6d13a7f..13e318e 100644 --- a/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh +++ b/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh @@ -4,4 +4,4 @@ set -e curl -X POST http://${GATEWAY_URL}/scw \ -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ -H 'Content-Type: application/json' \ - -d '{"target":"$1","relative_url":"/$2"}' \ No newline at end of file + -d '{"target":"$1","relative_url":"$2"}' \ No newline at end of file diff --git a/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh b/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh index 6d13a7f..13e318e 100644 --- a/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh +++ b/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh @@ -4,4 +4,4 @@ set -e curl -X POST http://${GATEWAY_URL}/scw \ -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ -H 'Content-Type: application/json' \ - -d '{"target":"$1","relative_url":"/$2"}' \ No newline at end of file + -d '{"target":"$1","relative_url":"$2"}' \ No newline at end of file From 8961db9a1eb067f9779dfd5e64a78575ad19e314 Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Thu, 6 Apr 2023 19:44:26 +0200 Subject: [PATCH 15/18] feat: add auto your function to a deployed gateway --- functions/serverless-gateway-python/README.md | 17 +++++------------ functions/serverless-gateway-python/app.py | 6 +++--- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 4f699a6..5d62eb6 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -18,35 +18,28 @@ Make sure to export your gateway base URL (`GATEWAY_URL`) and an authentication ### Deploy your serverless API -Deploy your functions using: +Deploy your functions and add them automatically as endpoints to your serverless gateway using: ``` pip install -r requirements.txt -scw_serverless deploy app.py +scw_serverless deploy app.py --gateway-url ${GATEWAY_URL} --gateway-api-key ${GATEWAY_TOKEN} ``` -### Add routes to your functions in the gateway - -You can add your function to the gateway with a chosen relative path using: -``` -./scripts/add_function_to_gateway.sh http:// / -``` - -### Check your route has been added +### Check your endpoint has been added You can use: ``` ./list_gateway_endpoints.sh ``` -### Call your functions via the routes +### Call your function via its route You can use: ``` curl http://${GATEWAY_URL}/ ``` -### Delete your routes +### Delete your endpoint You can use: ``` diff --git a/functions/serverless-gateway-python/app.py b/functions/serverless-gateway-python/app.py index b829556..cf9b1f2 100644 --- a/functions/serverless-gateway-python/app.py +++ b/functions/serverless-gateway-python/app.py @@ -2,14 +2,14 @@ app = Serverless("serverless-api") -@app.func() +@app.func(relative_url="/func-a") def func_a(_event, _context): return "Hello from function A" -@app.func() +@app.func(relative_url="/func-b") def func_b(_event, _context): return "Hello from function B" -@app.func() +@app.func(relative_url="/func-c") def func_c(_event, _context): return "Hello from function C" \ No newline at end of file From ea1b3c342ebd92937f35689e59564552f8db1ca1 Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Tue, 11 Apr 2023 19:43:35 +0200 Subject: [PATCH 16/18] chore: upgrade scw-serverless version and apply related changes --- functions/serverless-gateway-python/README.md | 6 +++--- functions/serverless-gateway-python/app.py | 6 +++--- functions/serverless-gateway-python/requirements.txt | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 5d62eb6..4dd5c65 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -12,7 +12,7 @@ This example uses: Deploy the serverless gateway as a container following the Serverless Gateway project instructions. -Make sure to export your gateway base URL (`GATEWAY_URL`) and an authentication token (`GATEWAY_TOKEN`) +Make sure to export your gateway base URL (`GATEWAY_HOST`) and an authentication token (`TOKEN`) ## Running @@ -22,7 +22,7 @@ Deploy your functions and add them automatically as endpoints to your serverless ``` pip install -r requirements.txt -scw_serverless deploy app.py --gateway-url ${GATEWAY_URL} --gateway-api-key ${GATEWAY_TOKEN} +scw-serverless deploy app.py --gateway-url https://${GATEWAY_HOST} --gateway-api-key ${TOKEN} ``` ### Check your endpoint has been added @@ -36,7 +36,7 @@ You can use: You can use: ``` -curl http://${GATEWAY_URL}/ +curl http://${GATEWAY_HOST}/ ``` ### Delete your endpoint diff --git a/functions/serverless-gateway-python/app.py b/functions/serverless-gateway-python/app.py index cf9b1f2..3099c76 100644 --- a/functions/serverless-gateway-python/app.py +++ b/functions/serverless-gateway-python/app.py @@ -2,14 +2,14 @@ app = Serverless("serverless-api") -@app.func(relative_url="/func-a") +@app.get(url="/func-a") def func_a(_event, _context): return "Hello from function A" -@app.func(relative_url="/func-b") +@app.get(url="/func-b") def func_b(_event, _context): return "Hello from function B" -@app.func(relative_url="/func-c") +@app.get(url="/func-c") def func_c(_event, _context): return "Hello from function C" \ No newline at end of file diff --git a/functions/serverless-gateway-python/requirements.txt b/functions/serverless-gateway-python/requirements.txt index e69e888..c5a00e0 100644 --- a/functions/serverless-gateway-python/requirements.txt +++ b/functions/serverless-gateway-python/requirements.txt @@ -1 +1 @@ -scw-serverless~=0.0.4 \ No newline at end of file +scw-serverless~=1.0.0 \ No newline at end of file From a765533781a64799758800723752601b5ff4a6d4 Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Wed, 12 Apr 2023 14:25:45 +0200 Subject: [PATCH 17/18] chore: use https instead of http --- functions/serverless-gateway-python/README.md | 4 ++-- .../scripts/add_function_to_gateway.sh | 2 +- .../scripts/delete_function_from_gateway.sh | 2 +- .../scripts/list_gateway_endpoints.sh | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/functions/serverless-gateway-python/README.md b/functions/serverless-gateway-python/README.md index 4dd5c65..b059b54 100644 --- a/functions/serverless-gateway-python/README.md +++ b/functions/serverless-gateway-python/README.md @@ -36,13 +36,13 @@ You can use: You can use: ``` -curl http://${GATEWAY_HOST}/ +curl https://${GATEWAY_HOST}/ ``` ### Delete your endpoint You can use: ``` -./scripts/delete_function_to_gateway.sh http:// / +./scripts/delete_function_to_gateway.sh https:// / ``` diff --git a/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh b/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh index 13e318e..2a9237a 100644 --- a/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh +++ b/functions/serverless-gateway-python/scripts/add_function_to_gateway.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -curl -X POST http://${GATEWAY_URL}/scw \ +curl -X POST https://${GATEWAY_URL}/scw \ -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ -H 'Content-Type: application/json' \ -d '{"target":"$1","relative_url":"$2"}' \ No newline at end of file diff --git a/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh b/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh index 13e318e..2a9237a 100644 --- a/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh +++ b/functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -curl -X POST http://${GATEWAY_URL}/scw \ +curl -X POST https://${GATEWAY_URL}/scw \ -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ -H 'Content-Type: application/json' \ -d '{"target":"$1","relative_url":"$2"}' \ No newline at end of file diff --git a/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh b/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh index 843bd46..9f95f05 100644 --- a/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh +++ b/functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -curl http://${GATEWAY_URL}/scw -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ No newline at end of file +curl https://${GATEWAY_URL}/scw -H 'X-Auth-Token: ${GATEWAY_TOKEN}' \ No newline at end of file From 3ddbee35af38d08fc4fcdc3f2b5ae4ee06b205b2 Mon Sep 17 00:00:00 2001 From: Reda Noureddine Date: Wed, 12 Apr 2023 14:26:05 +0200 Subject: [PATCH 18/18] chore: use scw-serverless v1.0.1 --- functions/serverless-gateway-python/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/serverless-gateway-python/requirements.txt b/functions/serverless-gateway-python/requirements.txt index c5a00e0..fdd6a7b 100644 --- a/functions/serverless-gateway-python/requirements.txt +++ b/functions/serverless-gateway-python/requirements.txt @@ -1 +1 @@ -scw-serverless~=1.0.0 \ No newline at end of file +scw-serverless==1.0.1 \ No newline at end of file