- Newest
- Most votes
- Most comments
Hello,
I'd suggest you use Greengrass IPC to read the configuration instead of using command line: https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-component-configuration.html#ipc-operation-getconfiguration.
Failing that, use environment variables instead of the command line. Windows commandline is going to remove quotes or otherwise complicate your life no matter what, so you do really need to avoid passing complex configurations that way.
run:
script: py -3 -u {artifacts:decompressedPath}/src/main.py
setEnv:
MyKey: "{configuration:/GGV2PubSubSdkConfig}"
Cheers,
Michael
Providing the solution I implemented based on Michaels answer above....
I used your suggestion of utilizing an environment variable for the substitution to avoid the double quotes getting removed from the command line substitution. My modified recipe manifest looks like this now...
"Run": {
"Script": "py -3 -u {artifacts:decompressedPath}/src/main.py GGV2PubSubSdkConfig",
"SetEnv": {
"GGV2PubSubSdkConfig": "{configuration:/GGV2PubSubSdkConfig}"
},
"RequiresPrivilege": "false"
Note: I still included a single command line parameter that indicates the name of the environment variable. This allowed me to avoid hard-coding the name of the variable in main.py.
Below if the change I made to the template main.py...
ggv2_component_config = os.environ[sys.argv[1]]
ggv2_component_config = json.loads(ggv2_component_config)
This solved my issue and the no other changes were required to get the template code running.
Relevant content
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 10 months ago
Thank you Michael. I was able to solve my problem following your suggestion to use an environment variable instead.