Get a Secrets Manager secret value using the Kotlin Amazon SDK - Amazon Secrets Manager
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Get a Secrets Manager secret value using the Kotlin Amazon SDK

For Kotlin applications, call the SDK directly with GetSecretValue or BatchGetSecretValue.

The following code example shows how to get a Secrets Manager secret value.

Required permissions: secretsmanager:GetSecretValue

suspend fun getValue(secretName: String?) { val valueRequest = GetSecretValueRequest { secretId = secretName } SecretsManagerClient { region = "us-east-1" }.use { secretsClient -> val response = secretsClient.getSecretValue(valueRequest) val secret = response.secretString println("The secret value is $secret") } }