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!