skip to Main Content

Suppose I wanted to store something like:

{
    "service_name": {
        "prod": "SECRET1",
        "dev": "SECRET2"
    }
}

Can I store such JSON in AWS Secrets Manager?

2

Answers


  1. Yes – regardless of the JSON structure, to AWS, you will be storing a string (SecretString), or binary.

    Creating the secret:

    aws secretsmanager create-secret 
        --name TestSecret 
        --description "Test secret" 
        --secret-string "{"service_name":{"prod":"SECRET1","dev":"SECRET2"}}"
    

    Retrieving the secret:

    aws secretsmanager get-secret-value 
        --secret-id TestSecret 
        --query SecretString 
        --output text
    

    Output:

    {"service_name":{"prod":"SECRET1","dev":"SECRET2"}}
    
    Login or Signup to reply.
  2. Just to add on to Ermiya’s answer, if you have that json in a file (or variable) you can easily serialize/deserialize it using jq. Given:

    $ cat file
    {
        "service_name": {
            "prod": "SECRET1",
            "dev": "SECRET2"
        }
    }
    

    then creating the secret:

    $ aws secretsmanager create-secret 
        --name TestSecret 
        --description "Test secret" 
        --secret-string "$(jq '. | @json' file)"
    

    retrieving the secret:

    $ aws secretsmanager get-secret-value 
        --secret-id TestSecret 
        --query SecretString 
        --output text | jq -r '.'
    {"service_name":{"prod":"SECRET1","dev":"SECRET2"}}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search