Back

[SOLVED] Function deployment deploys older deployment in the appwrite cloud

  • 0
  • Functions
  • Cloud
Matej
17 Jul, 2023, 20:25

Hi.

Here's what's being happening to me with cloud functions.

So, I have some test cloud function that returns some json data.

When I change my function file locally and run appwrite deploy function command, it deploys a code that was previously in the file, not the latest version.

If I run the command again, it will deploy the latest version I have.

For some reason I have to make two deployments in order to make latest one actually being deployed.

Has anyone experienced this?

TL;DR
The user is experiencing a problem where deploying a function in the appwrite cloud deploys an older version of the code instead of the latest one. They have tried activating the latest deployment in the appwrite console but still see the data format from the previous version in the logs. They mention that they have to run the deployment command twice in order for the latest version to be deployed. They provide a code snippet of their function and ask if anyone has experienced the same issue. There is no solution provided in the thread.
Matej
17 Jul, 2023, 20:26
TypeScript
const sdk = require("node-appwrite");

/*
  'req' variable has:
    'headers' - object with request headers
    'payload' - request body data as a string
    'variables' - object with function variables

  'res' variable has:
    'send(text, status)' - function to return text response. Status code defaults to 200
    'json(obj, status)' - function to return JSON response. Status code defaults to 200

  If an error is thrown, a response with code 500 will be returned.
*/

module.exports = async function (req, res) {
  const client = new sdk.Client();

  // You can remove services you don't use
  const account = new sdk.Account(client);
  const avatars = new sdk.Avatars(client);
  const database = new sdk.Databases(client);
  const functions = new sdk.Functions(client);
  const health = new sdk.Health(client);
  const locale = new sdk.Locale(client);
  const storage = new sdk.Storage(client);
  const teams = new sdk.Teams(client);
  const users = new sdk.Users(client);

  if (
    !req.variables['APPWRITE_FUNCTION_ENDPOINT'] ||
    !req.variables['APPWRITE_FUNCTION_API_KEY']
  ) {
    console.warn("Environment variables are not set. Function cannot use Appwrite SDK.");
  } else {
    client
      .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
      .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
      .setKey(req.variables['APPWRITE_FUNCTION_API_KEY'])
      .setSelfSigned(true);
  }

  res.json({
    req: req.variables['APPWRITE_FUNCTION_API_KEY'],
    env: process.env.TEST,
    hello: 'World'
  });
};

This is the function whole code and only changes I am currently making is inside res.json just to see different outputs in the logs

D5
17 Jul, 2023, 21:38

Did you have selected the function when deploying?

D5
17 Jul, 2023, 21:38

I mean, selected it with the space bar

Matej
17 Jul, 2023, 21:42

Yes

D5
17 Jul, 2023, 21:44

Then not sure

D5
17 Jul, 2023, 21:44

You're using visual studio code?

Matej
17 Jul, 2023, 21:44

Yeah

Matej
17 Jul, 2023, 21:44

I can maybe make a one minute video if needed

D5
17 Jul, 2023, 22:13

Then not sure what could be happening. I'm using VS code without inconveniences. Maybe you didn't saved the file previously? I think it's not probably, but just in case πŸ˜…

Matej
17 Jul, 2023, 22:20

I did save it

D5
17 Jul, 2023, 22:20

I supposed 😬

D5
17 Jul, 2023, 22:20

Then not sure what's happening

Matej
17 Jul, 2023, 22:22

These are the steps I do

  • Make a change in my index file and save it
  • make a deployment
  • deployment gets in the appwrite console and I activate that deployment
  • I run execution
  • In logs I see the data format from previous version
  • I run deployment again without any code changes
  • I activate deployment in the console
  • I run the execution
  • Latest data format is now shown in the logs
Matej
17 Jul, 2023, 23:41

Update.

I tried to deploy a second function.

First time deployment - I saw it being built inside appwrite console as it was being deployed and it disappeared after 2 seconds.

Then I had to run deploy command again to deploy it.

🀷

Drake
18 Jul, 2023, 01:07

deployment gets in the appwrite console and I activate that deployment

I think it gets activated automatically so you may be activating the old one

Matej
18 Jul, 2023, 09:13

I click to activate the latest one I see built in the console, I didn't know it's automatic

D5
18 Jul, 2023, 10:15

That seems to be the problem

D5
18 Jul, 2023, 10:15

You're activating the old one

Matej
18 Jul, 2023, 11:07

Ah it seems I actually was. πŸ‘€

Sory, all good then.

Matej
18 Jul, 2023, 11:07

[SOLVED] Function deployment deploys older deployment in the appwrite cloud

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more