issue deployment python code unable to open a file that is present on the core device

0

Hi,

i encounter an issue with component deployment on greengrass device. I made a python code opening a local json file for reading. I added every components in my deployment and it's working fine. But when the component start, i have an error : no such file or directory i connected to the core device and i can see all files (specially the json file) presents on the deployment package. if i run python localy, it works fine, the file is opened and rode. File permissions are good.

so i was wondering if :

  • it could be a sequence issue, the python code is starting maybe before the json file is downloaded on the core device?
  • it could be a path issue, the file is located on the same folder as the python code, command to open the file is : rawDatas=open('file.json') ?
  • i should verify the file is present before going to Run section of component, if it's the case, how can i do that ?
  • is there is any naming convention for files ? the file name is : 'read-my-file.json'
  • you have any idea to help me tshoot this?

FYI, i included python modules to the component and i modified the PYTHONPATH to point out this folder. as the code is running well (no error from module i import) but maybe there is an incidence on the lookup for files to open (once again, the json file is located on the same folder as the python code)

Any idea?

THX

profile picture
demandé il y a un an255 vues
2 réponses
1

To add onto Riku's comment, if the JSON file is part of the component deployment, it will be available at the start of your script. Checkout the component_dependency_name:artifacts:decompressedPath variable in your recipe. Use that along with Riku's code to validate.

Hope this helps!

AWS
Gavin_A
répondu il y a un an
0

Make sure that the json file may be running faster than it is being uploaded.
For example, try adding the following function to your code and see if the file exists in the same directory.
If you cannot see the json file from the python program, then it is running faster than the upload.

import subprocess
tmp = subprocess.run(['ls', '-l'])
print(tmp)
profile picture
EXPERT
répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions