I've created a function with the CDF UI using a zip file containing the handler.py file and requirements.txt.
In the handler.py file I have some imports for the cognite.client and pandas, then some data wrangling using client.assets and then the handle function.
I don't have the login code for the cognite client within the code in handler.py as I've understood that is not needed on runtime.
When calling the function from CDF UI, I receive the error related to the "client" as it doesn't recognizes it.
Should I provide an .env file within the zip file along with the code for instantiating the CogniteClient()? Or provide the needed env vars as secrets when creating the function from UI?
Nevermind, I've solved it with .env file, config.yaml and creating the CogniteClient() inside handler.py.
You have solved the problem but it is not the best approach. You don’t need to neither instantiate the client not use the config or env file.
Based on the error “client is not defined”, I am thinking that you are not passing the “client” as the first argument for the function hence the error.
You should have two parameters for you function.
The client parameter automatically gets passed to the function by the wrapper program and you don’t need to do anything except use it inside your function.
The second parameter is used to pass other function-specific parameters.
Please let me know if this resolves the issue otherwise I can provide further guidance.
Thank you for your answer, but initially this was how I've uploaded my function and tried to run it with the 2 parameters (client, data) . It throws the error I printed in the first post. I don't pass anything for data as it's not needed.
I've gone through all the examples for function in documentation and in cognitedata repos so I think I've tried to use it as understood from materials.
It may be related to specific rights in CDF? I am able to create and run the function so it wouldn't be this.
Sounds good. Thanks for your reply!