Lambda
We’re overhauling Dgraph’s docs to make them clearer and more approachable. If you notice any issues during this transition or have suggestions, please let us know.
Introduction
For Shared and Free backends, a Dgraph lambda script is uniquely identified by a deployment id associated with the backend. You can identify your backend and the associated deployment id by using the List Backends API. In case of a Dedicated, and multi-tenant backend, an additional key, the tenant id is also required to uniquely identify a lambda script. This tenant id key is ignored when used in the context of Shared and Free backends.
As a first step, you will need to identify your backend.
List Deployment and Get Lambda Script
Use the List Backends API to identify your backend,
as well as get the lambda script deployed. In order to list the backends, you
will need to pass a Bearer token as an Authorization
header. This token is
generated by logging in via the Login query
first.
Cloud Endpoint
API Command
Arguments
None
Example
The uid
field in the response of the query is to be used as the deployment id.
In the above example, the deployment id for the backend with name “OrderJourney”
is “0x6238”. The field lambdaScript
contains the lambda script in the form of
a Base64 encoded string.
Decode the Base64 encoded lambdaScript
In order to decode the Base64 encoded string into the actual lambda code, please use the command as shown below.
Output
Lambda Logs
You can fetch the logs for your lambda by using the getLambdaLogs
query.
Cloud Endpoint
API Command
Arguments
lambdaLogsInput
: a LambdaLogsInput objectlambdaLogsInput.deploymentID
: the deployment UID returned from [List Backends]((./backend#list-backends)lambdaLogsInput.tenantID
: In case of a multi-tenant, and dedicated backend, you will need to pass the tenant Id as welllambdaLogsInput.start
: start timelambdaLogsInput.end
: end time
Example
Update or Delete Lambda
You can update or delete your lambda by using the updateLambda
mutation. You
will need to pass a deployment id to uniquely identify your lambda. In case your
backend is multi-tenant, you will need to pass the tenant Id as well.
In order to update your lambda, you would need to convert your lamdba script
into a Base64 encoded format and send it as the lambdaScript
argument. In
order to delete your lambda, you can simply send in an empty string in the
lambdaScript
argument.
Cloud Endpoint
API Command
Arguments
updateLambdaInput
: an UpdateLambdaInput objectupdateLambdaInput.deploymentID
: the deployment UID returned from [List Backends]((./backend#list-backends)updateLambdaInput.tenantID
: the tenant ID in case your backend is a dedicated, and multi-tenant backend. In case you have any other type of backend, you can leave it as the default0
valueupdateLambdaInput.lambdaScript
: the base64-encoded Javascript string containing your Lambda Resolver
Example
- Create your Lambda Resolver script
- Base64 encode your script
- Send in a cURL request
Was this page helpful?