2

I am trying to create a lambda function that uses netCDF4. Unfortunately it seems netCDF4 is not supported in AWS. Is there a way to use netCDF4 in AWS?

Update: I created the zip file, however another module is missing (netCDF4._netCDF4) within the module I originally created the zip file for. Has anyone actually used specifically netCDF4 in a lambda function? Thanks in advance!

Arec
  • 33
  • 4

1 Answers1

1

Is there a way to use netCDF4 in AWS?

Yes. There are three options for you:

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • After creating the zip for netCDF4, another module appears to be missing. Here is the error: { "errorMessage": "Unable to import module 'lambda_function': No module named 'netCDF4._netCDF4'", "errorType": "Runtime.ImportModuleError", "stackTrace": [] } – Arec Jun 18 '21 at 03:08
  • @Arec Just create container lambda. This is the easiest way to handle lambda dependencies. Everything else is more complex to handle. – Marcin Jun 18 '21 at 03:15
  • Honestly it seems more complex than the first option. I am still new to AWS, but I appreciate your help. I feel like I did everything correctly with the first option (which I just watched a YouTube video since I find it easier to follow along), but some how another module is missing. – Arec Jun 18 '21 at 03:44
  • @Arec Doesn't netCDF4 depend on C libraries as well? AWS lambda will not have them either. – Marcin Jun 18 '21 at 03:50
  • When I pip install netCDF4, in the netCDF directory, _netCDF4.cp39-win_amd64.pyd is the only thing that is close to the _netCDF4 that is missing. Is this file related to the issue? – Arec Jun 18 '21 at 04:16
  • lambda environment is not windows. Seems you are install `win_` based dependencies. – Marcin Jun 18 '21 at 04:24
  • Any recommendations? – Arec Jun 18 '21 at 05:19
  • If I can't find the linux version of netCDF4, is my only option is to run my code in an ec2 instance? – Arec Jun 20 '21 at 20:22
  • @Arec You can install it in lambda container and lambda layer, or create your dependencies package on Amazon Linux 2. – Marcin Jun 20 '21 at 21:43
  • I'm using layers but it's not working. After adding the layer to the function, when I test the function it still doesn't recognize the package. Does my python version must match the version of the lambda function and layer? I have python3.9 – Arec Jun 21 '21 at 04:16
  • I would suggest making a new question with exact steps you take to create the layer and relevant error messages. – Marcin Jun 21 '21 at 04:17
  • I got it to work! I forgot I had a laptop with Linux. I just pip installed netCDF4 into a directory along with the python file and zipped it. I was able to upload the dependency via zip file but i was unable to use a layer. I completed the layer just like i did with uploading the zip file except not zipping the python file with it. Nevertheless, thank you for helping me. – Arec Jun 26 '21 at 03:40
  • @Arec Glad it worked out. If my answer and comments were helpful, it's acceptance would be appreciated. – Marcin Jun 26 '21 at 03:41