Get a Secrets Manager secret value using the Kotlin AWS SDK - AWS Secrets Manager
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Get a Secrets Manager secret value using the Kotlin AWS 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.fromEnvironment { region = "us-east-1" }.use { secretsClient -> val response = secretsClient.getSecretValue(valueRequest) val secret = response.secretString println("The secret value is $secret") } }