2

I'm retrieving an aws parameter store value using aws ssm command. I get the result back. I need to store this value in a shell variable so that I can use it later on.

This on Mac terminal. I am invoking through AWS CLI to get the aws parameters I get the values from aws however I can't set it to a shell variable due to my lack of knowledge of using Shell

export PASS=echo "$(aws ssm get-parameters --names "/enterprise/org/dev/spring.datasource.password" --with-decryption --query "Parameters[0].Value" | tr -d '"')"
echo $PASS

When I do echo $PASS I expect to see the value of the parameter however I don't get anything. I am sure that the value exist because if I don't export and just run $ aws ssm get-parameters. I see the result.

codeforester
  • 39,467
  • 16
  • 112
  • 140
user3553141
  • 109
  • 3
  • 9

1 Answers1

4

The right way to assign the output of your command to the variable is:

export PASS=$(aws ssm get-parameters --names "/enterprise/org/dev/spring.datasource.password" --with-decryption --query "Parameters[0].Value" | tr -d '"')

The way you are doing it, this is what shell does:

  • it sets PASS to "echo"
  • it runs the aws command pipeline and interprets the output as a command and tries to run it

Related:

codeforester
  • 39,467
  • 16
  • 112
  • 140