Amazon Web Services (AWS) - List Secrets using the AWS CLI

by
Jeremy Canfield |
Updated: June 02 2024
| Amazon Web Services (AWS) articles
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
The aws secretsmanager list-secrets command can be used the list the secrets you have created.
aws secretsmanager list-secrets
And here is an example of how to limit the output using the --query option
aws secretsmanager list-secrets --query 'SecretList[?Name==`my-secret`]'
Something like this should be returned.
{
"SecretList": [
{
"ARN": "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret-tD1U2U",
"Name": "my-secret",
"Description": "my-secret",
"LastChangedDate": "2023-08-23T17:23:54.741000-05:00",
"LastAccessedDate": "2023-08-22T19:00:00-05:00",
"SecretVersionsToStages": {
"0a8aa38f-b95e-42ab-acc9-7745aa710f23": [
"AWSCURRENT"
]
},
"CreatedDate": "2023-08-23T17:23:54.435000-05:00"
}
]
}
Or, the aws secretsmanager describe-secret command can be used to list a specific secret.
~]$ aws secretsmanager describe-secret --secret-id arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret-tD1U2U
{
"ARN": "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret-tD1U2U",
"Name": "my-secret",
"Description": "my-secret",
"LastChangedDate": "2023-08-25T16:30:15.716000+00:00",
"LastAccessedDate": "2023-08-25T00:00:00+00:00",
"VersionIdsToStages": {
"0a8aa38f-b95e-42ab-acc9-7745aa710f23": [
"AWSCURRENT"
]
},
"CreatedDate": "2023-08-23T22:23:54.435000+00:00"
}
Likewise, the aws secretsmanager get-secret-value command can be used to include the value of the secret.
~]$ aws secretsmanager list-secrets
{
"ARN": "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret-tD1U2U",
"Name": "my-secret",
"VersionId": "0a8aa38f-b95e-42ab-acc9-7745aa710f23",
"SecretString": "{\"username\":\"john.doe\",\"password\":\"itsasecret\"}",
"VersionStages": [
"AWSCURRENT"
],
"CreatedDate": "2023-08-23T22:23:54.737000+00:00"
}
Did you find this article helpful?
If so, consider buying me a coffee over at