Error when trying to use CLI to update Lambdas

You’ll need to update to use the new cloud admin endpoint.

Here is a working script that we are using via a husky powered git hook.


const fetch = require('node-fetch')
const fs = require('fs')

async function updateSlashLambdas() {
  try {
    fs.readFile('./DgraphLambdas/_final.js', async function (err, data) {
      if (err) return console.error(err)
      const lambdaScript = data.toString('base64')
      
      const updateLambdasQuery = `mutation UpdateDeployment($updateDeploymentInput: UpdateDeploymentInput!) {
          updateDeployment(input: $updateDeploymentInput)
      }
      `
      const response = await fetch(`https://cerebro.cloud.dgraph.io/graphql`, {
        headers: {
          'Content-Type': 'application/json',
          Authorization:
            'Bearer <TOKEN>',
        },
        method: 'POST',
        body: JSON.stringify({
          query: updateLambdasQuery,
          variables: {
            updateDeploymentInput: {
              uid: '0x2…',
              lambdaScript: lambdaScript,
            },
          },
        }),
      })
      const json = await response.json()
      if (json.errors) {
        throw json.errors
      }
      
      console.log(JSON.stringify(json))
    })
  } catch (error) {
      console.log(error);
  }
}
updateSlashLambdas()

1 Like