Get a Secrets Manager secret value using the Ruby 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 Ruby Amazon SDK

For Ruby applications, call the SDK directly with get_secret_value or batch_get_secret_value.

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

Required permissions: secretsmanager:GetSecretValue

# Use this code snippet in your app. # If you need more information about configurations or implementing the sample code, visit the AWS docs: # https://aws.amazon.com/developer/language/ruby/ require 'aws-sdk-secretsmanager' def get_secret client = Aws::SecretsManager::Client.new(region: '<<{{MyRegionName}}>>') begin get_secret_value_response = client.get_secret_value(secret_id: '<<{{MySecretName}}>>') rescue StandardError => e # For a list of exceptions thrown, see # https://<<{{DocsDomain}}>>/secretsmanager/latest/apireference/API_GetSecretValue.html raise e end secret = get_secret_value_response.secret_string # Your code goes here. end