I am trying to parse the response from aws secretsmanager
The output looks like:
{
"ARN": "arn:aws:secretsmanager:us-west-2:0000:secret:token-0000",
"Name": "token",
"VersionId": "0000-0000-0000-0000-0000",
"SecretString": "{\"TOKEN\":\"000000000000\"}",
"VersionStages": ["AWSCURRENT"],
"CreatedDate": "0000"
}
When attempting to parse this string with JSON.parse(), it attempts to parse the string value in SecretString which has escaped quotes.
I would have expected to need to JSON.parse the response in two steps however this does not work.
#!/bin/bash
TOKEN=$(node -e "\
const result = JSON.parse('$(aws secretsmanager get-secret-value --secret-id $ARN)'); \
const token = JSON.parse(result.SecretString); \
console.log(token); \
")
echo $TOKEN
How can I prevent the JSON.parse function from attempting to parse the string value of the SecretString - Alternatively, is there a better way to obtain the value?
aws secretsmanagerto a file then use Node.js to read and parse the content of the file. Or usejqinstead of Node.