Parsing secrets from AWS secrets manager using AWS cli
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The AWS CLI can retrieve secrets from AWS Secrets Manager in one command, but the output format often confuses people at first. The main detail to understand is that SecretString is usually returned as a JSON string inside a JSON response, so you often need one step to extract the field and another step to parse its contents.
Retrieve the Secret Value First
The base command is get-secret-value:
A typical response includes metadata plus either SecretString or SecretBinary. For secrets created in the console, SecretString often contains JSON such as a username and password pair.
If you only want the raw secret string, use a JMESPath query:
That removes the surrounding response object and prints only the secret payload.
Parse JSON Stored in SecretString
If the secret value itself is JSON, pipe it to jq:
Related reading
- Pass AWS credentials IAM role credentials to code running in Docker container
- Pause an Elastic Beanstalk app environment?
- Permission denied publickey when SSH Access to Amazon EC2 instance
- Persist local dynamoDB data in volumes lack permission - unable to open database file
- Password of rabbitmq system user
- PDO MySQL Use PDOATTR_EMULATE_PREPARES or not?
- PersistentVolumeClaim is stuck ''waiting for a volume to be created, either by external provisioner ebs.csi.aws.com'' on new AWS EKS cluster
- Pipe a stream to s3.upload

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.