Deploying to JellyFaaS
To do this, you will need to install the JellyCLI
, you can follow the steps here to do so.
Project set up
Firstly, you need to decided what language you want to develop your project in. At the moment, we support the following languages:
- Java
- Python
- Node
- C#
- GoLang
- Ruby
Once you have decided, cd
into the directory you wish to generate a template and run the following.
For reference, these are the required flags:
-d, --destination
-l, --language
-n, --name
Once it creates the project, open it in your favourite IDE of choice.
When you first open it, you may experience some dependency issues and there are a few default names, such as the package name, which may need to be changed.
The default in most cases is Example
.
The go.mod
file may have some missing dependencies (for go
users). We recommend deleting this and re-running the go mod init
and go mod tidy
commands.
Project Structure
Most of the project templates follow the same structure.
The file that will house your function code is the file highlighted with **___**
.
The README.md
file also has info on how to run your function locally.
.jellyfaasignore
This file works the same as the .gitignore file. It allows you to stop files from being deployed to the cloud function. This comes in handy if you have any extra large files, test files, etc... Per project, there are some default files that are excluded.
jellyspec.json
This file is used to package up your project and send it off to be hosted. It is key that the information in this file is correct as it can lead to many unexpected errors. It houses things like input/output schemas for files and json input/output data. Additionally, it describes what query parameters the function takes. For more information please see the Configuration section.
Writing the Function
./main.py
import functions_framework
from flask import jsonify
@functions_framework.http
def Example(request):
"""HTTP Cloud Function that greets a given name.
Args:
request (flask.Request): The request object.
<https://flask.palletsprojects.com/en/1.1.x/api/#incoming-request-data>
Returns:
"""
# your function code goes here
return None
./src/main/java/jfv1/Example.java
package jfv1;
import com.google.cloud.functions.HttpFunction;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;
import java.io.BufferedWriter;
import java.util.Optional;
public class Example implements HttpFunction {
@Override
public void service(final HttpRequest request, final HttpResponse response) throws Exception {
// your function code goes here
}
}
./function.go
./Function.cs
using Google.Cloud.Functions.Framework;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Text.Json;
using System.Threading.Tasks;
namespace ExampleProject
{
public class Example : IHttpFunction
{
private readonly ILogger<Example> _logger;
public Example(ILogger<Example> logger)
{
_logger = logger;
}
public async Task HandleAsync(HttpContext context)
{
var request = context.Request;
var response = context.Response;
// your function code goes here
}
}
}
Info
You can write what ever want with in each of the functions above (depending on the language you've chosen). This works exactly like a standard web server, expect you can only work with one endpoint. JellyFaaS functions (and cloud run functions in general) can only work with one end point. You can access what you'd expect when working with a web sever: you can get the request body, query parameters, headers etc... To find out more about Google's Functions Framework, click here.
Configuration
Once you've written your function, and you are thinking you are ready to deploy it, you must first complete the jellyspec.json
file.
jellyspec.json
file
Version: v1.0.0
Tip
There are some default values that are populated when you create your project. These might need to be changed.
runtime
is already filled out depending on the language you are using, you can change this to be a different run time environment.entrypoint
must be changed to match the name of the function you've written your code in the previous step.name
this isn't the identifier for your function, this is the user-friendly name for your function.shortname
this must be unique identifier for your function.inputJsonSchema
this follows the standard conversions for json schema. If you aren't sure what the conventions are, visit this official link.outputJsonSchema
this follows the standard conversions for json schema. If you aren't sure what the conventions are, visit this official link.
You can omit object fields in the jellyspec.json
file.
For example, if your function doesn't require any query parameters, you can remove this field.
However, you must include exactly ZERO or ONE of inputJsonSchema
or inputFile
and you must include exactly ZERO or ONE of outputJsonSchema
or outputFile
.
Likewise, if your function doesn't require any explicit input or output, you can remove the field.
{
"version": "1.0.0",
"name": "My Function Name",
"shortname": "my_unique_func",
"runtime": "python312",
"entrypoint": "MyEntrypoint",
"description": "A useful description of my function.",
"requirements": {
"requestType": "POST",
"queryParams": [
{
"name": "myKey",
"required": true, // Optional (Defaults to false)
"description": "A description of this param", // Optional
"exampleData": "myKey=42" // Optional
},
{
"name": "myKey2",
"required": false, // Optional (Defaults to false)
"description": "A description of this param", // Optional
"exampleData": "myKey2=some+value" // Optional
}
],
// Must include exactly ZERO or ONE of `inputJsonSchema` or `inputFile`
"inputJsonSchema": {
"$Schema": "https://json-schema.org/draft/2020-12/schema"
"description": "A description of the input section"
},
"inputFile": {
"extensions": ["png", "jpg", "jpeg"], // Optional
"required": true // Optional
"description": "A description of the input section"
},
// Must include exactly ZERO or ONE of `outputJsonSchema` or `outputFile`
"outputJsonSchema": {
"$Schema": "https://json-schema.org/draft/2020-12/schema"
"description": "A description of the input section"
},
"outputFile": {
"extensions": ["png", "jpg", "jpeg"] // Optional
"description": "A description of the input section"
}
},
"tags": [ // Optional
"weather",
"social"
]
}
Deploying
Once you have ensured your function is ready to deploy. Deploying is made easy with the CLI, all it takes is one command:
Tip
Its best to cd
out of your project's directory, so that the zip file doesn't get added to it.
This will generate a zip
file of your project and deploy it!