-
Notifications
You must be signed in to change notification settings - Fork 11
feat: python serverless api with serverless gateway #31
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
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
86793a9
feat: python serverless api with serverless gateway
redanrd b74ffc6
docs: add example readme
redanrd 95d84d1
fix: impement review
redanrd 220c56e
fix: impement review
redanrd 557cd8d
fix: impement review
redanrd a8ac65d
fix: implement review
redanrd cc566f1
fix: implement review
redanrd f7e986c
fix: implement review
redanrd 480bb66
fix: implement review
redanrd f61f73b
fix: implement review
redanrd 8883f8b
chore: update script start
redanrd d0de2d3
fix: implement review
redanrd aa8ac02
docs: call scripts as executables in readme
redanrd eec834b
fix: update relative path in scripts
redanrd 8961db9
feat: add auto your function to a deployed gateway
redanrd ea1b3c3
chore: upgrade scw-serverless version and apply related changes
redanrd a765533
chore: use https instead of http
redanrd 3ddbee3
chore: use scw-serverless v1.0.1
redanrd f5477ee
Merge branch 'main' into feat/serverless-gateway-example
redanrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 a serverless gateway 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 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://<function_domain_name> /<chosen_relative_path> | ||
``` | ||
|
||
### Check your route has been added | ||
|
||
You can use: | ||
``` | ||
./list_gateway_endpoints.sh | ||
``` | ||
|
||
### Call your functions via the routes | ||
|
||
You can use: | ||
``` | ||
curl http://${GATEWAY_URL}/<chosen_relative_path> | ||
``` | ||
|
||
### Delete your routes | ||
|
||
You can use: | ||
``` | ||
./scripts/delete_function_to_gateway.sh http://<function_domain_name> /<chosen_relative_path> | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scw-serverless~=0.0.4 |
7 changes: 7 additions & 0 deletions
7
functions/serverless-gateway-python/scripts/add_function_to_gateway.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
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"}' |
7 changes: 7 additions & 0 deletions
7
functions/serverless-gateway-python/scripts/delete_function_from_gateway.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
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"}' |
4 changes: 4 additions & 0 deletions
4
functions/serverless-gateway-python/scripts/list_gateway_endpoints.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
curl http://${GATEWAY_URL}/scw -H 'X-Auth-Token: ${GATEWAY_TOKEN}' | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.