BatchGetSecretValueCommand

Retrieves the contents of the encrypted fields SecretString or SecretBinary for up to 20 secrets. To retrieve a single secret, call GetSecretValue.

To choose which secrets to retrieve, you can specify a list of secrets by name or ARN, or you can use filters. If Secrets Manager encounters errors such as AccessDeniedException while attempting to retrieve any of the secrets, you can see the errors in Errors in the response.

Secrets Manager generates CloudTrail GetSecretValue log entries for each secret you request when you call this action. Do not include sensitive information in request parameters because it might be logged. For more information, see Logging Secrets Manager events with CloudTrail .

Required permissions: secretsmanager:BatchGetSecretValue, and you must have secretsmanager:GetSecretValue for each secret. If you use filters, you must also have secretsmanager:ListSecrets. If the secrets are encrypted using customer-managed keys instead of the Amazon Web Services managed key aws/secretsmanager, then you also need kms:Decrypt permissions for the keys. For more information, see IAM policy actions for Secrets Manager  and Authentication and access control in Secrets Manager .

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { SecretsManagerClient, BatchGetSecretValueCommand } from "@aws-sdk/client-secrets-manager"; // ES Modules import
// const { SecretsManagerClient, BatchGetSecretValueCommand } = require("@aws-sdk/client-secrets-manager"); // CommonJS import
const client = new SecretsManagerClient(config);
const input = { // BatchGetSecretValueRequest
  SecretIdList: [ // SecretIdListType
    "STRING_VALUE",
  ],
  Filters: [ // FiltersListType
    { // Filter
      Key: "description" || "name" || "tag-key" || "tag-value" || "primary-region" || "owning-service" || "all",
      Values: [ // FilterValuesStringList
        "STRING_VALUE",
      ],
    },
  ],
  MaxResults: Number("int"),
  NextToken: "STRING_VALUE",
};
const command = new BatchGetSecretValueCommand(input);
const response = await client.send(command);
// { // BatchGetSecretValueResponse
//   SecretValues: [ // SecretValuesType
//     { // SecretValueEntry
//       ARN: "STRING_VALUE",
//       Name: "STRING_VALUE",
//       VersionId: "STRING_VALUE",
//       SecretBinary: new Uint8Array(),
//       SecretString: "STRING_VALUE",
//       VersionStages: [ // SecretVersionStagesType
//         "STRING_VALUE",
//       ],
//       CreatedDate: new Date("TIMESTAMP"),
//     },
//   ],
//   NextToken: "STRING_VALUE",
//   Errors: [ // APIErrorListType
//     { // APIErrorType
//       SecretId: "STRING_VALUE",
//       ErrorCode: "STRING_VALUE",
//       Message: "STRING_VALUE",
//     },
//   ],
// };

Example Usage

 Loading code editor

BatchGetSecretValueCommand Input

See BatchGetSecretValueCommandInput for more details

Parameter
Type
Description
Filters
Filter[] | undefined

The filters to choose which secrets to retrieve. You must include Filters or SecretIdList, but not both.

MaxResults
number | undefined

The number of results to include in the response.

If there are more results available, in the response, Secrets Manager includes NextToken. To get the next results, call BatchGetSecretValue again with the value from NextToken. To use this parameter, you must also use the Filters parameter.

NextToken
string | undefined

A token that indicates where the output should continue from, if a previous call did not show all results. To get the next results, call BatchGetSecretValue again with this value.

SecretIdList
string[] | undefined

The ARN or names of the secrets to retrieve. You must include Filters or SecretIdList, but not both.

BatchGetSecretValueCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
Errors
APIErrorType[] | undefined

A list of errors Secrets Manager encountered while attempting to retrieve individual secrets.

NextToken
string | undefined

Secrets Manager includes this value if there's more output available than what is included in the current response. This can occur even when the response includes no values at all, such as when you ask for a filtered view of a long list. To get the next results, call BatchGetSecretValue again with this value.

SecretValues
SecretValueEntry[] | undefined

A list of secret values.

Throws

Name
Fault
Details
DecryptionFailure
client

Secrets Manager can't decrypt the protected secret text using the provided KMS key.

InternalServiceError
server

An error occurred on the server side.

InvalidNextTokenException
client

The NextToken value is invalid.

InvalidParameterException
client

The parameter name or value is invalid.

InvalidRequestException
client

A parameter value is not valid for the current state of the resource.

Possible causes:

  • The secret is scheduled for deletion.

  • You tried to enable rotation on a secret that doesn't already have a Lambda function ARN configured and you didn't include such an ARN as a parameter in this call.

  • The secret is managed by another service, and you must use that service to update it. For more information, see Secrets managed by other Amazon Web Services services .

ResourceNotFoundException
client

Secrets Manager can't find the resource that you asked for.

SecretsManagerServiceException
Base exception class for all service exceptions from SecretsManager service.