Using my own python package in different greengrass components

0

Hi all.
I want to use my own python package in different components.
Is there any ways to handle this?

preguntada hace 3 años857 visualizaciones
4 Respuestas
0
Respuesta aceptada

Hello,
You can create a single component which only holds the common dependencies. Do the same thing with the dependency artifact with regard to zipping and unzipping. Then use the dependencies by adding a Greengrass dependency in your component onto the dependency component in the recipe. With the dependency added, you can now use {<dependency component name>:artifacts:decompressedPath}/dependencies.

Now you have a path which can be shared with several components and they will all use the exact same dependencies.

Cheers,
Michael

AWS
EXPERTO
respondido hace 3 años
profile picture
EXPERTO
revisado hace un mes
0

Hello and thank you for your interest in Greengrass,
Since you used the word "component" I'm assuming that you are using Greengrass V2, please let me know if that is not the case.

When you say that you want to use your own Python package I take this to mean that you have a directory containing a Python module or modules which you want to import to your main script which Greengrass executes. To do this, I can recommend that you ZIP up your dependencies, which I will call dependencies.zip. You will then upload this file to S3 and add it as an artifact of your Greengrass component's recipe. Additionally specify "Unarchive: ZIP" option for this artifact, this way Greengrass will unzip the file on the device.

Now on the device we have a directory full of the modules that you want to use, so we need to tell Python where to find them. We do this using PYTHONPATH. Update the lifecycle run or startup script to be:

PYTHONPATH={artifacts:decompressedPath}/dependencies python3 -u <your script
>```

Note that we are setting the PYTHONPATH to be {artifacts:decompressedPath}/dependencies. The /dependencies is added because the name of the zip file was "dependencies.zip" and we will unzip it into a directory with the same name as the filename without the extension.  
  
  
Hope this helps.  
Cheers,  
Michael
AWS
EXPERTO
respondido hace 3 años
0

Thank you, for answer.
You are right, I'm using Greengrass V2 and you understood my question correct.
What you recommended didn't quite work for me.
I have few components, for example: A and B. All of them need some python library, let it be 'dependencies'.
If I use PYTHONPATH like this:
PYTHONPATH={artifacts:decompressedPath}/dependencies
the PYTHONPATH available only for component, where it defined. So I need to attach the same dependencies to each components.
And when I updated dependencies, I need to update every components.
But is there any better way, when I updated dependencies all components get newest version of it without redeployment.

As an idea I can make a component 'dependencies' which will be used like a library, but how can I provide the path to the latest version of dependencies component to all components when dependencies was updated?
Thanks for any advices.

respondido hace 3 años
0

Thank you very much. This is what I wanted. Everything works fine.

respondido hace 3 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas