aws / amazon-ssm-agent

An agent to enable remote management of your EC2 instances, on-premises servers, or virtual machines (VMs).
https://aws.amazon.com/systems-manager/
Apache License 2.0
1.04k stars 323 forks source link

SSM unable to read environment variable on EC2 #427

Closed phbissiwu closed 2 years ago

phbissiwu commented 2 years ago

I am working on something and I am trying to call some environment variables with SSM run command using AWS-RunShellScript. but for some reason, this returns nothing. Please how can I call environment variables with SSM AWS-RunShellScript?

Thank you.

Thor-Bjorgvinsson commented 2 years ago

Thanks for reaching out @phbissiwu, Agent does not propagate process environment variables to aws:runshellscript. Here is example output from print environment variables within AWS-RunShellScript execution:

AWS_SSM_INSTANCE_ID=<InstanceId>
_=/usr/bin/env
LANG=en_US.UTF-8
AWS_SSM_PLATFORM_NAME=<PlatformName>
INVOCATION_ID=<InvocationId>
AWS_SSM_PLATFORM_VERSION=<PlatformVersion>
PWD=/usr/bin
JOURNAL_STREAM=<JournalStream>
SSM_COMMAND_ID=<commandId>
SHLVL=2
AWS_SSM_REGION_NAME=us-east-1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

You can see what variables are available in your script by running env in AWS-RunShellScript.