Solved

Cognite functions deployment issues

  • 14 October 2022
  • 3 replies
  • 123 views

Userlevel 1

Hi! 

After switching from experimental to cognite-sdk 3.9.0 I struggle with deployment. 

1: Using handle

If i try to deploy using the handle, then the requirements are not handled. The function deploys, but failing at the imports. How should requiremenents be used when deploying like this? 

Imports are inside handle():

def handle(client, data, secrets):    from googleapiclient.discovery import build    from googleapiclient.errors import HttpError

Creating function like this:

cognite_client.functions.create(    name=function_name,    external_id=function_ext_id,    function_handle=handle)

2 - Using a folder.

Then I get this error: 

[WinError 267] The directory name is invalid: 'C:\\Users\\hknap\\AppData\\Local\\Temp\\tmptzkywbdl\\function.zip'

If I debug, the folder “tmptzkywbdl” is created, so there should be no permission issues. 

 

3- Manually uploading the zip file

This works (including the requirements.txt), thanks for adding this possibility. It is just a little extra hassle ;)  would prefer if 1 was working. 

 

 

Regards,

icon

Best answer by Henrik Eiding 14 October 2022, 17:13

View original

3 replies

Hi, Håvard!

  1. You’re correct, when using the function_handle argument, the requirements.txt is not included in the function deployment. However, this was also the case when using the experimental SDK. To get your requirements in when using the function_handle argument, you can list your packages in the docstring of the function, as documented beneath he examples here and in this image: 

     

  2. I’m not sure why this error occurs. Even though it looks like there are no permission issues, I suggest you try to use the latest version of the SDK - we have made some improvements on how we handle the creation of temporary folders.                                                                                                    
  3. Yes, both 1 and 2 should work. If option 2 still does not work with the latest SDK, please file a support ticket, and we will try to provide a fix.

I hope that helps!

Userlevel 3

Hi @Håvard Knappskog

Was Henrik’s answer above helpful for you? 

 

Userlevel 1

Hi! 

Thanks, yes it is helpful. 

If I insert the requirements like suggested for method 1, I get the same error as for method 2. 

I will try to upgrade to the latest version from 3.9. 

Reply