9

Parsing JSON parameters stored in AWS Parameter Store using jq

 3 years ago
source link: https://alexanderzeitler.com/articles/parsing-json-parameters-stored-in-aws-parameter-store-using-jq/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Alexander Zeitler

Parsing JSON parameters stored in AWS Parameter Store using jq

Published on Tuesday, January 7, 2020

The other day I had the idea to store some JSON as a AWS Parameter Store value.

If you read the parameter using AWS CLI:

aws ssm get-parameters --name /prod/some-json-param

you get something like this:

{
"Parameters": [
{
"Name": "/prod/some-json-param",
"Type": "String",
"Value": "{\n \"server\": \"\",\n \"token\": \"\"\n}",
"Version": 2,
"LastModifiedDate": 1578353153.788,
"ARN": "arn:aws:ssm:eu-central-1:1234567890:parameter/prod/some-json-param"
}
],
"InvalidParameters": []
}

What I wanted to get in a shell script, was the JSON representation of Value like this:

{
"server": "",
"token": ""
}

Thanks to the popular jq command, this is quite easy:

aws ssm get-parameters --name /prod/some-json-param | jq '.Parameters | .[] | .Value'

That way, we get the value of Value as a string:

"{\n  \"server\": \"\",\n  \"token\": \"\"\n}"

Another call to jq will give us the desired result:

aws ssm get-parameters --name /prod/some-json-param | jq '.Parameters | .[] | .Value' | jq '.|fromjson'
{
"server": "",
"token": ""
}

Happy Coding!


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK