Component with bash script and python code - how to package/deploy

0

I have created an AWS Greengrass component that consists of:

  • A python program
  • A bash script, called as a subprocess from within that Python program.

I have it packaged/deployed as follows:

  • .py file and .sh script zipped in my_archive.zip
  • stored on S3:/path/to/my_archive.zip

Snippet from recipe file is as follows:
"Manifests": [
{
"Platform": {
"os": "linux"
},
"Lifecycle": {
"Run": "python3 -u {artifacts:decompressedPath}/my_archive/my_python_file.py "
},
"Artifacts": [
{
"URI": "sS3:/path/to/my_archive.zip ",
"Unarchive": "ZIP",
"Permission": {
"Read": "ALL",
"Execute": "ALL"
}
}
]
}
]

Within the code, the python file executes "subprocess.run" assuming that the script file is local:
process = subprocess.Popen(["./my_bash_script.sh",
"-i",
args])

The logs report "file not found", and when I run "ls -ltrh" with the subprocess call within the component to debug, it reports 0 files.

My question is -

  1. How do I get the deployed .sh filepath, relative to the python script, to be able to call it with the "subprocess" call?
질문됨 3년 전744회 조회
1개 답변
0

Hi GreengrassUser,

Thanks for using Greengrass V2. You cannot find the file from the artifacts:decompressedPath from the component process because when the lifecycle command runs its working directory will be set to the component's work path, i.e. <greengrass_root>/work/<component_name>, as described in the documentation here https://docs.aws.amazon.com/greengrass/v2/developerguide/component-recipe-reference.html and you can verify $PWD from your component process. So you can access the file from the artifacts:decompressedPath by passing the path either as an environment variable or as an argument to your python script run lifecycle command as {artifacts:decompressedPath}/my_archive/my_bash_script.sh i.e. same as you run the python script.

Thanks,
Shagupta

AWS
답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠