How do I access Greengrass Core environment variables in AWS System Manager Run Command

0

I have AWS systems manager managed node setup for a greengrass core device and want to run command to execute shell script. The shell script needs to access greengrass core environment variables $AWS_IOT_THING_NAME to process. However, I do not see any value returned by $AWS_IOT_THING_NAME.

  1. Is there a different mechanism to access the greengrass env variables by the AWS SSM run command?
  2. I can see that the SourceId of the node is same as the AWS_IOT_THING_NAME. Can I access it inside a shell script as environmental variable?

I need to execute a script to run on multiple devices which uploads images to the s3 bucket with folder name {AWS_IOT_THING_NAME}/images. I know this can be done using custom greengrass component, but I want to try it using the AWS SSM fleet manager.

raghak
已提問 1 年前檢視次數 290 次
1 個回答
0

Hi,

SSM Agent is not able to access Greengrass variables since it is not executed as a child process of Greengrass, but as an independent process executed by systemd, even when you deploy it via aws.greengrass.SystemManagerAgent component.

What you can do is to write a component that export that variable so that it is available to the script run by the SSM Agent. One example would be to write that ThingName in a file inside /var/ or /etc/ folders, and then read it from your script before executing it. Alternatively the custom component could add an export to the .bashrc file of the SSM Agent user and execute your script in bash.

Cheers,

Massimiliano

AWS
專家
已回答 1 年前
  • Hi Massimiliano, Is there a way to get the Managed node "SourceId" using the SSM run command to run a shell script?

  • Could you please explain what you are trying to do?

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南