Skip to content

Instantly share code, notes, and snippets.

@trickyearlobe
Created January 15, 2020 03:06
Show Gist options
  • Save trickyearlobe/9247525d80933f2a2ac896a64033674c to your computer and use it in GitHub Desktop.
Save trickyearlobe/9247525d80933f2a2ac896a64033674c to your computer and use it in GitHub Desktop.
require 'aws-sdk-secretsmanager'
require 'base64'
def get_aws_secret(secret_name,region_name)
client = Aws::SecretsManager::Client.new(region: region_name)
begin
get_secret_value_response = client.get_secret_value(secret_id: secret_name)
rescue Aws::SecretsManager::Errors::DecryptionFailure => e
raise
rescue Aws::SecretsManager::Errors::InternalServiceError => e
raise
rescue Aws::SecretsManager::Errors::InvalidParameterException => e
raise
rescue Aws::SecretsManager::Errors::InvalidRequestException => e
raise
rescue Aws::SecretsManager::Errors::ResourceNotFoundException => e
raise
else
if get_secret_value_response.secret_string
secret = get_secret_value_response.secret_string
else
decoded_binary_secret = Base64.decode64(get_secret_value_response.secret_binary)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment