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
asked a year ago242 views
2 Answers
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
answered a year ago
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
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions